godown 3.0.0-canary.8 → 3.0.0-canary.9

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 (242) hide show
  1. package/components/alert.js +1 -1
  2. package/components/avatar.d.ts +1 -0
  3. package/components/avatar.d.ts.map +1 -1
  4. package/components/avatar.js +3 -2
  5. package/components/avatar.js.map +1 -1
  6. package/components/breath.d.ts +1 -0
  7. package/components/breath.d.ts.map +1 -1
  8. package/components/breath.js +3 -2
  9. package/components/breath.js.map +1 -1
  10. package/components/button.d.ts +12 -6
  11. package/components/button.d.ts.map +1 -1
  12. package/components/button.js +14 -11
  13. package/components/button.js.map +1 -1
  14. package/components/card.d.ts +1 -2
  15. package/components/card.d.ts.map +1 -1
  16. package/components/card.js +5 -10
  17. package/components/card.js.map +1 -1
  18. package/components/carousel.d.ts +5 -4
  19. package/components/carousel.d.ts.map +1 -1
  20. package/components/carousel.js +2 -1
  21. package/components/carousel.js.map +1 -1
  22. package/components/details.d.ts +4 -1
  23. package/components/details.d.ts.map +1 -1
  24. package/components/details.js +4 -1
  25. package/components/details.js.map +1 -1
  26. package/components/dialog.d.ts +4 -1
  27. package/components/dialog.d.ts.map +1 -1
  28. package/components/dialog.js +5 -2
  29. package/components/dialog.js.map +1 -1
  30. package/components/dragbox.d.ts +7 -7
  31. package/components/dragbox.d.ts.map +1 -1
  32. package/components/dragbox.js +1 -1
  33. package/components/dragbox.js.map +1 -1
  34. package/components/flex.d.ts +1 -0
  35. package/components/flex.d.ts.map +1 -1
  36. package/components/flex.js +8 -0
  37. package/components/flex.js.map +1 -1
  38. package/components/form.d.ts +0 -2
  39. package/components/form.d.ts.map +1 -1
  40. package/components/form.js +0 -2
  41. package/components/form.js.map +1 -1
  42. package/components/grid.d.ts +7 -2
  43. package/components/grid.d.ts.map +1 -1
  44. package/components/grid.js +1 -0
  45. package/components/grid.js.map +1 -1
  46. package/components/input.d.ts +2 -2
  47. package/components/input.d.ts.map +1 -1
  48. package/components/input.js +2 -2
  49. package/components/input.js.map +1 -1
  50. package/components/layout.d.ts +2 -5
  51. package/components/layout.d.ts.map +1 -1
  52. package/components/layout.js +16 -4
  53. package/components/layout.js.map +1 -1
  54. package/components/link.d.ts +3 -1
  55. package/components/link.d.ts.map +1 -1
  56. package/components/link.js +3 -1
  57. package/components/link.js.map +1 -1
  58. package/components/progress.d.ts +1 -10
  59. package/components/progress.d.ts.map +1 -1
  60. package/components/progress.js +5 -14
  61. package/components/progress.js.map +1 -1
  62. package/components/range.d.ts +12 -11
  63. package/components/range.d.ts.map +1 -1
  64. package/components/range.js +4 -11
  65. package/components/range.js.map +1 -1
  66. package/components/rotate.d.ts +1 -1
  67. package/components/rotate.d.ts.map +1 -1
  68. package/components/rotate.js +1 -1
  69. package/components/rotate.js.map +1 -1
  70. package/components/router.d.ts +6 -8
  71. package/components/router.d.ts.map +1 -1
  72. package/components/router.js +9 -9
  73. package/components/router.js.map +1 -1
  74. package/components/select.d.ts +1 -2
  75. package/components/select.d.ts.map +1 -1
  76. package/components/select.js +1 -2
  77. package/components/select.js.map +1 -1
  78. package/components/skeleton.d.ts.map +1 -1
  79. package/components/skeleton.js +2 -2
  80. package/components/skeleton.js.map +1 -1
  81. package/components/split.d.ts +17 -0
  82. package/components/split.d.ts.map +1 -1
  83. package/components/split.js +42 -17
  84. package/components/split.js.map +1 -1
  85. package/components/switch.d.ts +3 -3
  86. package/components/switch.d.ts.map +1 -1
  87. package/components/switch.js +5 -5
  88. package/components/switch.js.map +1 -1
  89. package/components/text.js +2 -2
  90. package/components/time.d.ts +4 -4
  91. package/components/time.d.ts.map +1 -1
  92. package/components/time.js +1 -9
  93. package/components/time.js.map +1 -1
  94. package/components/tooltip.d.ts +11 -1
  95. package/components/tooltip.d.ts.map +1 -1
  96. package/components/tooltip.js +19 -5
  97. package/components/tooltip.js.map +1 -1
  98. package/components/typewriter.d.ts +2 -2
  99. package/components/typewriter.d.ts.map +1 -1
  100. package/components/typewriter.js +2 -2
  101. package/components/typewriter.js.map +1 -1
  102. package/core/global-style.d.ts.map +1 -1
  103. package/core/global-style.js +8 -1
  104. package/core/global-style.js.map +1 -1
  105. package/core/super-anchor.js +1 -1
  106. package/core/super-input.d.ts +2 -2
  107. package/core/super-input.d.ts.map +1 -1
  108. package/core/super-input.js.map +1 -1
  109. package/custom-elements.json +1 -1
  110. package/dev/components/avatar.d.ts +1 -0
  111. package/dev/components/avatar.d.ts.map +1 -1
  112. package/dev/components/avatar.js +1 -3
  113. package/dev/components/avatar.js.map +1 -1
  114. package/dev/components/breath.d.ts +1 -0
  115. package/dev/components/breath.d.ts.map +1 -1
  116. package/dev/components/breath.js +1 -0
  117. package/dev/components/breath.js.map +1 -1
  118. package/dev/components/button.d.ts +12 -6
  119. package/dev/components/button.d.ts.map +1 -1
  120. package/dev/components/button.js +18 -13
  121. package/dev/components/button.js.map +1 -1
  122. package/dev/components/card.d.ts +1 -2
  123. package/dev/components/card.d.ts.map +1 -1
  124. package/dev/components/card.js +21 -28
  125. package/dev/components/card.js.map +1 -1
  126. package/dev/components/carousel.d.ts +5 -4
  127. package/dev/components/carousel.d.ts.map +1 -1
  128. package/dev/components/carousel.js +1 -0
  129. package/dev/components/carousel.js.map +1 -1
  130. package/dev/components/details.d.ts +4 -1
  131. package/dev/components/details.d.ts.map +1 -1
  132. package/dev/components/details.js +3 -0
  133. package/dev/components/details.js.map +1 -1
  134. package/dev/components/dialog.d.ts +4 -1
  135. package/dev/components/dialog.d.ts.map +1 -1
  136. package/dev/components/dialog.js +4 -1
  137. package/dev/components/dialog.js.map +1 -1
  138. package/dev/components/dragbox.d.ts +7 -7
  139. package/dev/components/dragbox.d.ts.map +1 -1
  140. package/dev/components/dragbox.js.map +1 -1
  141. package/dev/components/flex.d.ts +1 -0
  142. package/dev/components/flex.d.ts.map +1 -1
  143. package/dev/components/flex.js +8 -0
  144. package/dev/components/flex.js.map +1 -1
  145. package/dev/components/form.d.ts +0 -2
  146. package/dev/components/form.d.ts.map +1 -1
  147. package/dev/components/form.js +0 -2
  148. package/dev/components/form.js.map +1 -1
  149. package/dev/components/grid.d.ts +7 -2
  150. package/dev/components/grid.d.ts.map +1 -1
  151. package/dev/components/grid.js +1 -0
  152. package/dev/components/grid.js.map +1 -1
  153. package/dev/components/input.d.ts +2 -2
  154. package/dev/components/input.d.ts.map +1 -1
  155. package/dev/components/input.js +1 -1
  156. package/dev/components/input.js.map +1 -1
  157. package/dev/components/layout.d.ts +2 -5
  158. package/dev/components/layout.d.ts.map +1 -1
  159. package/dev/components/layout.js +15 -3
  160. package/dev/components/layout.js.map +1 -1
  161. package/dev/components/link.d.ts +3 -1
  162. package/dev/components/link.d.ts.map +1 -1
  163. package/dev/components/link.js +3 -1
  164. package/dev/components/link.js.map +1 -1
  165. package/dev/components/progress.d.ts +1 -10
  166. package/dev/components/progress.d.ts.map +1 -1
  167. package/dev/components/progress.js +3 -12
  168. package/dev/components/progress.js.map +1 -1
  169. package/dev/components/range.d.ts +12 -11
  170. package/dev/components/range.d.ts.map +1 -1
  171. package/dev/components/range.js +3 -10
  172. package/dev/components/range.js.map +1 -1
  173. package/dev/components/rotate.d.ts +1 -1
  174. package/dev/components/rotate.d.ts.map +1 -1
  175. package/dev/components/rotate.js.map +1 -1
  176. package/dev/components/router.d.ts +6 -8
  177. package/dev/components/router.d.ts.map +1 -1
  178. package/dev/components/router.js +9 -9
  179. package/dev/components/router.js.map +1 -1
  180. package/dev/components/select.d.ts +1 -2
  181. package/dev/components/select.d.ts.map +1 -1
  182. package/dev/components/select.js +0 -1
  183. package/dev/components/select.js.map +1 -1
  184. package/dev/components/skeleton.d.ts.map +1 -1
  185. package/dev/components/skeleton.js.map +1 -1
  186. package/dev/components/split.d.ts +17 -0
  187. package/dev/components/split.d.ts.map +1 -1
  188. package/dev/components/split.js +41 -16
  189. package/dev/components/split.js.map +1 -1
  190. package/dev/components/switch.d.ts +3 -3
  191. package/dev/components/switch.d.ts.map +1 -1
  192. package/dev/components/switch.js +7 -7
  193. package/dev/components/switch.js.map +1 -1
  194. package/dev/components/time.d.ts +4 -4
  195. package/dev/components/time.d.ts.map +1 -1
  196. package/dev/components/time.js +1 -9
  197. package/dev/components/time.js.map +1 -1
  198. package/dev/components/tooltip.d.ts +11 -1
  199. package/dev/components/tooltip.d.ts.map +1 -1
  200. package/dev/components/tooltip.js +28 -8
  201. package/dev/components/tooltip.js.map +1 -1
  202. package/dev/components/typewriter.d.ts +2 -2
  203. package/dev/components/typewriter.d.ts.map +1 -1
  204. package/dev/components/typewriter.js +0 -1
  205. package/dev/components/typewriter.js.map +1 -1
  206. package/dev/core/global-style.d.ts.map +1 -1
  207. package/dev/core/global-style.js +8 -9
  208. package/dev/core/global-style.js.map +1 -1
  209. package/dev/core/super-input.d.ts +2 -2
  210. package/dev/core/super-input.d.ts.map +1 -1
  211. package/dev/core/super-input.js.map +1 -1
  212. package/index.js +13 -13
  213. package/package.json +1 -1
  214. package/src/components/avatar.ts +2 -3
  215. package/src/components/breath.ts +2 -0
  216. package/src/components/button.ts +26 -16
  217. package/src/components/card.ts +22 -27
  218. package/src/components/carousel.ts +7 -4
  219. package/src/components/details.ts +5 -1
  220. package/src/components/dialog.ts +6 -1
  221. package/src/components/dragbox.ts +8 -7
  222. package/src/components/flex.ts +6 -1
  223. package/src/components/form.ts +1 -2
  224. package/src/components/grid.ts +11 -2
  225. package/src/components/input.ts +3 -2
  226. package/src/components/layout.ts +6 -8
  227. package/src/components/link.ts +3 -1
  228. package/src/components/progress.ts +6 -12
  229. package/src/components/range.ts +15 -20
  230. package/src/components/rotate.ts +1 -1
  231. package/src/components/router.ts +18 -9
  232. package/src/components/select.ts +2 -2
  233. package/src/components/skeleton.ts +2 -0
  234. package/src/components/split.ts +48 -17
  235. package/src/components/switch.ts +12 -8
  236. package/src/components/time.ts +8 -4
  237. package/src/components/tooltip.ts +29 -8
  238. package/src/components/typewriter.ts +10 -3
  239. package/src/core/global-style.ts +9 -9
  240. package/src/core/super-input.ts +2 -2
  241. package/vscode.html-custom-data.json +1 -1
  242. package/web-types.json +1 -1
@@ -13,11 +13,8 @@ const protoName = "layout";
13
13
  * {@linkcode NavLayout} renders slot and optional top header, bottom footer.
14
14
  *
15
15
  * @slot - The main content of the layout.
16
- *
17
16
  * @slot header - The header of the layout.
18
- *
19
17
  * @slot footer - The footer of the layout.
20
- *
21
18
  * @category layout
22
19
  */
23
20
  @godown(protoName)
@@ -50,21 +47,22 @@ const protoName = "layout";
50
47
  )
51
48
  class NavLayout extends GlobalStyle {
52
49
  /**
53
- * If true, hide the header slot.
50
+ * If true, remove the header slot.
54
51
  */
55
52
  @property({ type: Boolean })
56
- noHeader: boolean;
53
+ noHeader = false;
54
+
57
55
  /**
58
- * If true, hide the footer slot.
56
+ * If true, remove the footer slot.
59
57
  */
60
58
  @property({ type: Boolean })
61
- noFooter: boolean;
59
+ noFooter = false;
62
60
 
63
61
  /**
64
62
  * If true, header will sticky.
65
63
  */
66
64
  @property({ type: Boolean })
67
- sticky: boolean;
65
+ sticky = false;
68
66
 
69
67
  protected render() {
70
68
  return html`${
@@ -19,7 +19,9 @@ class Link extends SuperAnchor {
19
19
  /**
20
20
  * If "push", call `history.pushState`.
21
21
  *
22
- * If "replace", call `history.replaceState`
22
+ * If "replace", call `history.replaceState`.
23
+ *
24
+ * If "normal", behave like a normal anchor.
23
25
  */
24
26
  @property()
25
27
  type: "push" | "replace" | "normal" = "normal";
@@ -1,5 +1,6 @@
1
1
  import { godown } from "@godown/element/decorators/godown.js";
2
2
  import { styles } from "@godown/element/decorators/styles.js";
3
+ import { isNil } from "@godown/element/tools/lib.js";
3
4
  import { css, html } from "lit";
4
5
  import { property } from "lit/decorators.js";
5
6
 
@@ -56,26 +57,19 @@ const protoName = "progress";
56
57
  }
57
58
  `)
58
59
  class Progress extends GlobalStyle {
59
- /**
60
- * Maximum.
61
- */
62
60
  @property({ type: Number })
63
61
  max = 1;
64
- /**
65
- * Minimum.
66
- */
62
+
67
63
  @property({ type: Number })
68
64
  min = 0;
69
- /**
70
- * Input value.
71
- */
72
- @property({ type: Number, reflect: true })
73
- value = null;
65
+
66
+ @property({ type: Number })
67
+ value: number;
74
68
 
75
69
  protected render() {
76
70
  let width = 20;
77
71
  let className: string;
78
- if (this.value !== null) {
72
+ if (!isNil(this.value)) {
79
73
  width = this.parsePercent(this.value);
80
74
  className = "static";
81
75
  }
@@ -133,33 +133,36 @@ class Range extends SuperInput {
133
133
  step: number;
134
134
 
135
135
  /**
136
- * Display vertically
136
+ * Display vertically.
137
137
  */
138
138
  @property({ type: Boolean, reflect: true })
139
139
  vertical: boolean;
140
140
 
141
141
  /**
142
- * When `this.range` is true, it should be [number, number], otherwise number.
142
+ * Value, or each of values, will render a handle.
143
+ *
144
+ * Accepts number or array of numbers.
143
145
  */
144
146
  @property({ type: Array })
145
147
  value: number | number[];
148
+
146
149
  /**
147
- * The default of `this.value`.
150
+ * The default of `{@linkcode this.value}`.
148
151
  */
149
152
  @property({ type: Array })
150
153
  default: typeof this.value;
151
154
 
152
155
  @part("root")
153
- _root: HTMLElement;
156
+ protected _root: HTMLElement;
154
157
 
155
158
  @queryAll("[part=handle]")
156
- _handles: NodeListOf<HTMLElement>;
159
+ protected _handles: NodeListOf<HTMLElement>;
157
160
 
158
161
  @state()
159
162
  lastFocus?: number;
160
163
 
161
164
  /**
162
- * Returns true when the second number is greater than the first number
165
+ * Returns true when the second number is greater than the first number.
163
166
  */
164
167
  get reverse() {
165
168
  return this.range ? this.value[0] > this.value[1] : false;
@@ -279,8 +282,8 @@ class Range extends SuperInput {
279
282
  };
280
283
  }
281
284
 
282
- createMouseDown(index) {
283
- return (e) => {
285
+ createMouseDown(index: number) {
286
+ return (e: MouseEvent) => {
284
287
  this.focusHandle(index);
285
288
  this.createMousedownListener(this.createSetValue(index))(e);
286
289
  };
@@ -292,7 +295,7 @@ class Range extends SuperInput {
292
295
  this.focusHandle(0);
293
296
  }
294
297
 
295
- createSetValue(index?: number) {
298
+ createSetValue(index: number) {
296
299
  return (numberOrModifier: number | ((value: number) => number)) => {
297
300
  const number = typeof numberOrModifier === "number"
298
301
  ? this.normalizeValue(numberOrModifier)
@@ -386,21 +389,13 @@ class Range extends SuperInput {
386
389
  this.value = this.default;
387
390
  }
388
391
 
389
- swap() {
390
- if (this.range) {
391
- const [a, b] = this.value as [number, number];
392
- this.value = [b, a];
393
- }
394
- }
395
-
396
392
  sort() {
397
- this.value = this.toSorted();
393
+ return this.value = this.toSorted();
398
394
  }
399
395
 
400
- toSorted(): typeof this.value {
396
+ toSorted() {
401
397
  if (this.range) {
402
- const [a, b] = this.value as [number, number];
403
- return a > b ? [b, a] : [a, b];
398
+ return [...this.value as number[]].sort((a, b) => a - b);
404
399
  }
405
400
  return this.value;
406
401
  }
@@ -49,7 +49,7 @@ const cssScope = scopePrefix(protoName);
49
49
  )
50
50
  class Rotate extends GlobalStyle {
51
51
  @part("root")
52
- _root: HTMLElement;
52
+ protected _root: HTMLElement;
53
53
 
54
54
  protected render() {
55
55
  return html`<div part="root">
@@ -27,6 +27,8 @@ const protoName = "router";
27
27
  *
28
28
  * If no routes are matched, the default value (no named slot) will be rendered.
29
29
  *
30
+ * @slot - Display slot when there is no match.
31
+ * @slot * - Matching slot will be displayed.
30
32
  * @category navigation
31
33
  */
32
34
  @godown(protoName)
@@ -50,31 +52,37 @@ class Router<C = unknown> extends GlobalStyle {
50
52
  */
51
53
  @state()
52
54
  component: C | TemplateResult = null;
55
+
53
56
  /**
54
57
  * Dynamic parameters record.
55
58
  */
56
59
  @state()
57
60
  params: Record<string, string> = {};
61
+
58
62
  /**
59
63
  * Value of matched path in routes.
60
64
  */
61
65
  @state()
62
66
  path: string;
67
+
63
68
  /**
64
69
  * Current pathname (equals to location.pathname).
65
70
  */
66
71
  @property()
67
72
  pathname = "";
73
+
68
74
  /**
69
75
  * Path prefix.
70
76
  */
71
77
  @property()
72
78
  baseURL = "";
79
+
73
80
  /**
74
81
  * Rendered content when there is no match.
75
82
  */
76
83
  @state()
77
84
  default: TemplateResult = htmlSlot();
85
+
78
86
  /**
79
87
  * The type of routing sources.
80
88
  *
@@ -84,6 +92,7 @@ class Router<C = unknown> extends GlobalStyle {
84
92
  */
85
93
  @property()
86
94
  type: "united" | "slotted" | "field" = "united";
95
+
87
96
  /**
88
97
  * Cache accessed records.
89
98
  *
@@ -97,6 +106,7 @@ class Router<C = unknown> extends GlobalStyle {
97
106
  this.__routes = value;
98
107
  this.collectFieldRoutes(value);
99
108
  }
109
+
100
110
  get routes() {
101
111
  return this.__routes;
102
112
  }
@@ -158,8 +168,7 @@ class Router<C = unknown> extends GlobalStyle {
158
168
  }
159
169
 
160
170
  /**
161
- * @param params value of useRouter()
162
- * @param first whether this path is loaded for the first time.
171
+ * Callback function when the route changes.
163
172
  */
164
173
  routeChangeCallback: (params: {
165
174
  pathname: string;
@@ -182,9 +191,7 @@ class Router<C = unknown> extends GlobalStyle {
182
191
  }
183
192
 
184
193
  /**
185
- * Find components from {@linkcode __fieldRouteTree} matching query.
186
- * @param query Query string.
187
- * @returns Components or null.
194
+ * Get component from {@linkcode routes} by query.
188
195
  */
189
196
  fieldComponent(query?: string) {
190
197
  query ||= this.useWhich(this.pathname);
@@ -203,9 +210,7 @@ class Router<C = unknown> extends GlobalStyle {
203
210
  }
204
211
 
205
212
  /**
206
- * Find components from {@linkcode __slottedRouteTree} matching query.
207
- * @param query Query string.
208
- * @returns Named slot element template result or null.
213
+ * Get component from slotted elements by query.
209
214
  */
210
215
  slottedComponent(usedRouteTemplate?: string) {
211
216
  const slottedPaths = this._slottedNames;
@@ -256,9 +261,13 @@ class Router<C = unknown> extends GlobalStyle {
256
261
 
257
262
  static updateAll() {
258
263
  this.routerInstances.forEach((i) => {
259
- i.pathname = window.location.pathname;
264
+ i.handlePopstate();
260
265
  });
261
266
  }
267
+
268
+ handlePopstate = this.events.add(window, "popstate", () => {
269
+ this.pathname = location.pathname;
270
+ }) as () => void;
262
271
  }
263
272
 
264
273
  export default Router;
@@ -69,7 +69,6 @@ const protoName = "select";
69
69
  `,
70
70
  )
71
71
  class Select extends Input {
72
- _cache = new WeakMap<HTMLElement, boolean>();
73
72
  // @ts-ignore
74
73
  value: string | string[];
75
74
 
@@ -80,7 +79,7 @@ class Select extends Input {
80
79
  text: string;
81
80
 
82
81
  @part("content")
83
- _content: HTMLElement;
82
+ protected _content: HTMLElement;
84
83
 
85
84
  @property()
86
85
  direction: "top" | "bottom" | undefined;
@@ -93,6 +92,7 @@ class Select extends Input {
93
92
 
94
93
  @state()
95
94
  protected autoDirection: "top" | "bottom" = "bottom";
95
+
96
96
  protected lastChecked: HTMLElement;
97
97
  protected defaultText: string;
98
98
  protected defaultChecked: HTMLElement[];
@@ -91,12 +91,14 @@ class Skeleton extends GlobalStyle {
91
91
  */
92
92
  @property()
93
93
  type: "text" | "image";
94
+
94
95
  /**
95
96
  * Animation type.
96
97
  * opacity animation only effect on slotted element and image icon.
97
98
  */
98
99
  @property()
99
100
  animation: "position" | "opacity" = "position";
101
+
100
102
  /**
101
103
  * If false, render slot only.
102
104
  */
@@ -79,6 +79,7 @@ class Split extends SuperInput {
79
79
  */
80
80
  @property({ type: Number })
81
81
  len = 6;
82
+
82
83
  /**
83
84
  * Focus index.
84
85
  */
@@ -87,6 +88,7 @@ class Split extends SuperInput {
87
88
 
88
89
  @state()
89
90
  current = -1;
91
+
90
92
  @state()
91
93
  currentValue: (string | void)[] = [];
92
94
 
@@ -123,7 +125,32 @@ class Split extends SuperInput {
123
125
  if (this.compositing) {
124
126
  return;
125
127
  }
126
- if (e.data === null) {
128
+
129
+ this.fillInput(e.data);
130
+ this.value = this.currentValue.join("");
131
+
132
+ this.dispatchEvent(new CustomEvent("input", { detail: this.value, bubbles: true, composed: true }));
133
+ this.dispatchEvent(new CustomEvent("change", { detail: this.value, composed: true }));
134
+ }
135
+
136
+ /**
137
+ * Fill input with data.
138
+ *
139
+ * If data is null
140
+ * - If current value is null, move to before.
141
+ * - If current value is not null, delete it.
142
+ *
143
+ * If data is not null
144
+ * - If current value is null, input data.
145
+ * - If current value is not null, input data and move to after.
146
+ *
147
+ * If data is multiple characters,
148
+ * Fill input with data[0] and call fillInput with data.slice(1).
149
+ *
150
+ * @param data Input event data.
151
+ */
152
+ protected fillInput(data: string | null) {
153
+ if (data === null) {
127
154
  // delete
128
155
 
129
156
  if (this.currentValue[this.current] !== null) {
@@ -137,28 +164,32 @@ class Split extends SuperInput {
137
164
  const lastNotNull = this.currentValue.findLastIndex(a => a !== null);
138
165
  this.current = this.current - 1 < 0 ? lastNotNull < 0 ? 0 : lastNotNull : this.current - 1;
139
166
  }
140
- } else {
141
- // input
167
+ return;
168
+ }
142
169
 
143
- this.currentValue[this.current] = e.data;
144
- if (this.current + 1 >= this.len) {
145
- // index overflow
170
+ const multiple = data.length > 1;
146
171
 
147
- this.current = this.currentValue.indexOf(null);
148
- if (this.current === -1) {
149
- this.blur();
150
- }
151
- } else {
152
- // go to after
172
+ // input
173
+ this.currentValue[this.current] = data[0];
174
+ if (this.current + 1 >= this.len) {
175
+ // index overflow
153
176
 
154
- this.current += 1;
177
+ this.current = this.currentValue.indexOf(null);
178
+ if (this.current === -1) {
179
+ this.blur();
155
180
  }
156
- }
181
+ } else {
182
+ // go to after
157
183
 
158
- this.value = this.currentValue.join("");
184
+ this.current += 1;
185
+ }
159
186
 
160
- this.dispatchEvent(new CustomEvent("input", { detail: this.value, bubbles: true, composed: true }));
161
- this.dispatchEvent(new CustomEvent("change", { detail: this.value, composed: true }));
187
+ if (multiple) {
188
+ const after = data.slice(1);
189
+ if (after) {
190
+ this.fillInput(after);
191
+ }
192
+ }
162
193
  }
163
194
 
164
195
  focus() {
@@ -24,6 +24,7 @@ const cssScope = scopePrefix(protoName);
24
24
  ${cssScope}-width: 3em;
25
25
  ${cssScope}-height: calc(var(${cssScope}-width) / 2);
26
26
  ${cssScope}-handle-size: 1.25em;
27
+ ${cssScope}-handle-space: .125em;
27
28
  ${cssScope}-transition: .2s ease-in-out;
28
29
  background: var(${cssGlobalVars.input}-background);
29
30
  width: var(${cssScope}-width);
@@ -72,7 +73,7 @@ const cssScope = scopePrefix(protoName);
72
73
  }
73
74
 
74
75
  :host([checked]) span {
75
- transform: translateX(100%);
76
+ left: 50%;
76
77
  }
77
78
 
78
79
  .rect .true {
@@ -83,13 +84,13 @@ const cssScope = scopePrefix(protoName);
83
84
  background: var(${cssGlobalVars.passive});
84
85
  }
85
86
 
86
- .round span::after{
87
+ .round span{
87
88
  --size: var(${cssScope}-handle-size);
88
- content:"";
89
89
  border-radius: 100%;
90
90
  background: var(--godown--input-control);
91
91
  width: var(--size);
92
92
  height: var(--size);
93
+ margin: var(${cssScope}-handle-space);
93
94
  }
94
95
 
95
96
  .round {
@@ -107,21 +108,25 @@ class Switch extends SuperInput {
107
108
  */
108
109
  @property({ type: Boolean, reflect: true })
109
110
  round = false;
111
+
110
112
  /**
111
113
  * Whether this element is selected or not.
112
114
  */
113
115
  @property({ type: Boolean, reflect: true })
114
116
  checked = false;
117
+
115
118
  /**
116
- * Whether this element is disabled or not.
119
+ * Disable this element.
117
120
  */
118
121
  @property({ type: Boolean, reflect: true })
119
122
  disabled = false;
123
+
120
124
  /**
121
- * Parsed by JSON.parse to checked.
125
+ * Default checked state.
122
126
  */
123
127
  @property()
124
128
  default = "false";
129
+
125
130
  /**
126
131
  * Input value.
127
132
  */
@@ -129,7 +134,7 @@ class Switch extends SuperInput {
129
134
  value = "on";
130
135
 
131
136
  @query("input")
132
- _input: HTMLInputElement;
137
+ protected _input: HTMLInputElement;
133
138
 
134
139
  protected render() {
135
140
  return html`<div part="root" class="${this.round ? "round" : "rect"}">
@@ -142,8 +147,7 @@ class Switch extends SuperInput {
142
147
  id="${this.makeId}"
143
148
  type="checkbox"
144
149
  >
145
- <span class="${this.checked}">
146
- </span>
150
+ <span part="handle" class="${this.checked}"></span>
147
151
  </div>`;
148
152
  }
149
153
 
@@ -17,32 +17,36 @@ const protoName = "time";
17
17
  @styles(css`:host{text-align: center;}`)
18
18
  class Time extends GlobalStyle {
19
19
  /**
20
- * Cancels the next character formatting.
20
+ * Escape symbol.
21
21
  */
22
22
  @property()
23
23
  escape = "%";
24
+
24
25
  /**
25
26
  * Format strings.
26
27
  */
27
28
  @property()
28
29
  format = "YYYY-MM-DD hh:mm:ss UTFZ";
30
+
29
31
  /**
30
32
  * Time.
31
33
  */
32
34
  @property({ type: Object })
33
35
  time = new Date();
36
+
34
37
  /**
35
38
  * If there is a value, update every gap or timeout.
36
39
  */
37
40
  @property({ type: Number })
38
- timeout = 0;
41
+ timeout;
42
+
39
43
  /**
40
44
  * The number of milliseconds that change with each update.
41
45
  */
42
46
  @property({ type: Number })
43
- gap = 0;
47
+ gap;
44
48
 
45
- timeoutId: number;
49
+ protected timeoutId: number;
46
50
 
47
51
  protected render(): string {
48
52
  return fmtime(this.format, this.time, this.escape);
@@ -4,7 +4,7 @@ import { htmlSlot } from "@godown/element/directives/html-slot.js";
4
4
  import { css, html } from "lit";
5
5
  import { property } from "lit/decorators.js";
6
6
 
7
- import { cssGlobalVars, scopePrefix } from "../core/global-style.js";
7
+ import { scopePrefix } from "../core/global-style.js";
8
8
  import SuperOpenable, { type Direction8 } from "../core/super-openable.js";
9
9
 
10
10
  const protoName = "tooltip";
@@ -15,7 +15,7 @@ const cssScope = scopePrefix(protoName);
15
15
  *
16
16
  * If it has the tip property, ignore the slot tip.
17
17
  *
18
- * @slot tip - Tip element.
18
+ * @slot tip - Tip element if no `tim` provided.
19
19
  * @slot - Content.
20
20
  * @category feedback
21
21
  */
@@ -23,7 +23,7 @@ const cssScope = scopePrefix(protoName);
23
23
  @styles(
24
24
  css`
25
25
  :host {
26
- ${cssScope}--tip-background: var(${cssGlobalVars.background});
26
+ ${cssScope}--tip-background: inherit;
27
27
  display: inline-block;
28
28
  width: fit-content;
29
29
  }
@@ -44,9 +44,7 @@ const cssScope = scopePrefix(protoName);
44
44
  user-select: none;
45
45
  }
46
46
 
47
- :host([open]) [part="tip"],
48
- :host(:hover) [part="tip"],
49
- [part="tip"]:hover {
47
+ :host([open]) [part="tip"] {
50
48
  visibility: visible;
51
49
  }
52
50
 
@@ -76,11 +74,13 @@ class Tooltip extends SuperOpenable {
76
74
  */
77
75
  @property()
78
76
  tip: string;
77
+
79
78
  /**
80
79
  * Direction of opening the tip.
81
80
  */
82
81
  @property()
83
82
  direction: Direction8 = "top";
83
+
84
84
  /**
85
85
  * Content alignment.
86
86
  */
@@ -93,6 +93,18 @@ class Tooltip extends SuperOpenable {
93
93
  @property({ type: Boolean })
94
94
  propagation: boolean;
95
95
 
96
+ /**
97
+ * How can tips be triggered.
98
+ *
99
+ * If `focus`, element will be focusable, open tip when focused.
100
+ *
101
+ * If `hover`, element will open tip when hovered.
102
+ *
103
+ * @default "hover"
104
+ */
105
+ @property()
106
+ type: "hover" | "focus" = "hover";
107
+
96
108
  static aligns = {
97
109
  start: "flex-start",
98
110
  end: "flex-end",
@@ -103,9 +115,18 @@ class Tooltip extends SuperOpenable {
103
115
 
104
116
  protected render() {
105
117
  const align = Tooltip.aligns[this.align] || "inherit";
106
- return html`<div part="root" style="justify-content:${align};align-items:${align}">
118
+ const isFocusable = this.type === "focus";
119
+ return html`<div part="root"
120
+ tabindex="${isFocusable ? 0 : -1}"
121
+ @focus="${isFocusable ? () => this.open = true : null}"
122
+ @blur="${isFocusable ? () => this.open = false : null}"
123
+ @mouseenter="${isFocusable ? null : () => this.open = true}"
124
+ @mouseleave="${isFocusable ? null : () => this.open = false}"
125
+ style="justify-content:${align};align-items:${align}">
107
126
  ${htmlSlot()}
108
- <div part="tip" direction="${this.direction}" style="pointer-events:${this.propagation ? "none" : "all"}">
127
+ <div part="tip"
128
+ direction="${this.direction}"
129
+ style="pointer-events:${this.propagation ? "none" : "all"}">
109
130
  ${
110
131
  this.tip
111
132
  ? html`<span class="passive">${this.tip}</span>`