chiplet 0.4.0 → 0.5.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 (106) hide show
  1. package/dist/assets/{positioning.css.ts.vanilla-BVOg9Lwj.css → positioning.css.ts.vanilla-BLJ90UCF.css} +12 -12
  2. package/dist/component/button/LinkButton.js +1 -1
  3. package/dist/component/button/LinkButton.js.map +1 -1
  4. package/dist/component/button/index.js +1 -0
  5. package/dist/component/button/index.js.map +1 -1
  6. package/dist/component/checkbox/Checkbox.js +5 -1
  7. package/dist/component/checkbox/Checkbox.js.map +1 -1
  8. package/dist/component/checkbox/Radio.js +5 -1
  9. package/dist/component/checkbox/Radio.js.map +1 -1
  10. package/dist/component/checkbox/Switch.js +1 -1
  11. package/dist/component/checkbox/Switch.js.map +1 -1
  12. package/dist/component/header/Header.js +1 -1
  13. package/dist/component/header/Header.js.map +1 -1
  14. package/dist/component/index.js +1 -0
  15. package/dist/component/index.js.map +1 -1
  16. package/dist/component/input/Input.js +5 -1
  17. package/dist/component/input/Input.js.map +1 -1
  18. package/dist/component/input/SearchInput.js +4 -7
  19. package/dist/component/input/SearchInput.js.map +1 -1
  20. package/dist/component/menu/renderMenuItem.js +5 -1
  21. package/dist/component/menu/renderMenuItem.js.map +1 -1
  22. package/dist/component/select/Group.js +1 -1
  23. package/dist/component/select/Group.js.map +1 -1
  24. package/dist/component/select/Option.js +1 -1
  25. package/dist/component/select/Option.js.map +1 -1
  26. package/dist/hook/accessibility/keyboard/context/index.js.map +1 -1
  27. package/dist/hook/accessibility/keyboard/hook/useLastFocused.js.map +1 -1
  28. package/dist/hook/document/useHighlight.js +2 -4
  29. package/dist/hook/document/useHighlight.js.map +1 -1
  30. package/dist/hook/form/useGroup.js +17 -16
  31. package/dist/hook/form/useGroup.js.map +1 -1
  32. package/dist/hook/observable/useObservable.js +6 -1
  33. package/dist/hook/observable/useObservable.js.map +1 -1
  34. package/dist/hook/popover/style/positioning.css.js +1 -1
  35. package/dist/hook/popover/useAnchorPositioning.js +1 -1
  36. package/dist/hook/popover/useAnchorPositioning.js.map +1 -1
  37. package/dist/hook/popover/useLightDismiss.js +15 -0
  38. package/dist/hook/popover/useLightDismiss.js.map +1 -1
  39. package/dist/hook/popover/useOverlay.js +8 -5
  40. package/dist/hook/popover/useOverlay.js.map +1 -1
  41. package/dist/hook/popover/usePopover.js +11 -11
  42. package/dist/hook/popover/usePopover.js.map +1 -1
  43. package/dist/hook/popover/usePositioning.js +7 -12
  44. package/dist/hook/popover/usePositioning.js.map +1 -1
  45. package/dist/hook/popover/useReturnFocus.js.map +1 -1
  46. package/dist/hook/popover/useTooltip.js +4 -2
  47. package/dist/hook/popover/useTooltip.js.map +1 -1
  48. package/dist/hook/promise/usePromise.js +1 -1
  49. package/dist/hook/promise/usePromise.js.map +1 -1
  50. package/dist/hook/react/useActivate.js +3 -0
  51. package/dist/hook/react/useActivate.js.map +1 -1
  52. package/dist/hook/react/useConst.js +3 -2
  53. package/dist/hook/react/useConst.js.map +1 -1
  54. package/dist/hook/react/useRefCallback.js.map +1 -1
  55. package/dist/index.js +3 -0
  56. package/dist/index.js.map +1 -1
  57. package/dist/infra/logging/logger.js +6 -2
  58. package/dist/infra/logging/logger.js.map +1 -1
  59. package/dist/theme/index.js +2 -0
  60. package/dist/theme/index.js.map +1 -1
  61. package/dist/theme/useSystemColorScheme.js +16 -16
  62. package/dist/theme/useSystemColorScheme.js.map +1 -1
  63. package/dist/util/file/readAsDataURL.js +15 -4
  64. package/dist/util/file/readAsDataURL.js.map +1 -1
  65. package/dist/util/tree/attachChild.js +7 -1
  66. package/dist/util/tree/attachChild.js.map +1 -1
  67. package/dist/util/tree/detachChild.js +3 -0
  68. package/dist/util/tree/detachChild.js.map +1 -1
  69. package/package.json +17 -17
  70. package/src/component/button/LinkButton.tsx +3 -1
  71. package/src/component/button/index.ts +1 -0
  72. package/src/component/checkbox/Checkbox.tsx +7 -1
  73. package/src/component/checkbox/Radio.tsx +5 -1
  74. package/src/component/checkbox/Switch.tsx +1 -1
  75. package/src/component/header/Header.tsx +1 -1
  76. package/src/component/input/Input.tsx +5 -1
  77. package/src/component/input/SearchInput.tsx +9 -8
  78. package/src/component/menu/renderMenuItem.tsx +5 -1
  79. package/src/component/select/Group.tsx +1 -1
  80. package/src/component/select/Option.tsx +1 -1
  81. package/src/hook/accessibility/keyboard/context/index.ts +1 -1
  82. package/src/hook/accessibility/keyboard/hook/useLastFocused.ts +6 -0
  83. package/src/hook/document/useHighlight.ts +5 -4
  84. package/src/hook/form/useGroup.ts +17 -19
  85. package/src/hook/observable/useObservable.ts +14 -1
  86. package/src/hook/popover/style/positioning.css.ts +1 -1
  87. package/src/hook/popover/useAnchorPositioning.ts +1 -1
  88. package/src/hook/popover/useLightDismiss.ts +27 -0
  89. package/src/hook/popover/useOverlay.ts +15 -6
  90. package/src/hook/popover/usePopover.ts +11 -13
  91. package/src/hook/popover/usePositioning.ts +7 -15
  92. package/src/hook/popover/useReturnFocus.ts +12 -3
  93. package/src/hook/popover/useTooltip.ts +4 -3
  94. package/src/hook/promise/usePromise.ts +4 -1
  95. package/src/hook/react/useActivate.ts +8 -1
  96. package/src/hook/react/useConst.ts +3 -4
  97. package/src/hook/react/useRefCallback.ts +2 -0
  98. package/src/infra/logging/logger.ts +12 -2
  99. package/src/theme/global.css.ts +0 -27
  100. package/src/theme/index.ts +4 -0
  101. package/src/theme/useSystemColorScheme.ts +22 -20
  102. package/src/util/file/readAsDataURL.ts +17 -4
  103. package/src/util/number/index.ts +2 -0
  104. package/src/util/random/index.ts +4 -0
  105. package/src/util/tree/attachChild.ts +12 -1
  106. package/src/util/tree/detachChild.ts +6 -0
@@ -7,13 +7,26 @@ export function readAsDataURL(blob: Blob, signal?: AbortSignal | undefined) {
7
7
  return new Promise<string>((resolve, reject) => {
8
8
  const reader = new FileReader()
9
9
 
10
- reader.onabort = () => reject(AbortError())
10
+ const onAbort = () => reader.abort()
11
11
 
12
- reader.onerror = () => reject(reader.error)
12
+ const cleanup = () => signal?.removeEventListener('abort', onAbort)
13
13
 
14
- reader.onload = () => resolve(reader.result as string)
14
+ reader.onabort = () => {
15
+ cleanup()
16
+ reject(AbortError())
17
+ }
15
18
 
16
- signal?.addEventListener('abort', () => reader.abort(), { once: true })
19
+ reader.onerror = () => {
20
+ cleanup()
21
+ reject(reader.error)
22
+ }
23
+
24
+ reader.onload = () => {
25
+ cleanup()
26
+ resolve(reader.result as string)
27
+ }
28
+
29
+ signal?.addEventListener('abort', onAbort, { once: true })
17
30
 
18
31
  reader.readAsDataURL(blob)
19
32
 
@@ -1 +1,3 @@
1
1
  export * from './isNumber'
2
+
3
+ export type * from './range'
@@ -1,3 +1,7 @@
1
+ // 'generateDeterministicId' is deliberately not exported from this barrel:
2
+ // it imports '@vanilla-extract/css', which has side effects, so re-exporting
3
+ // it would pull them into every '#util' consumer. Import it by direct
4
+ // relative path instead.
1
5
  export * from './generateDigest'
2
6
  export * from './generateUniqueId'
3
7
  export * from './toHex'
@@ -1,13 +1,24 @@
1
+ import { detachChild } from './detachChild'
1
2
  import type { TreeNode } from './node'
2
3
 
3
4
  export function attachChild<T extends TreeNode<unknown>>(parent: T, child: T) {
5
+ // Detach a child that is still attached to a tree first so re-attaching
6
+ // cannot leave stale or self-referential links behind.
7
+ if (child.parent != null) {
8
+ detachChild(child.parent, child)
9
+ }
10
+
11
+ // Reset the child's sibling links so a node previously attached elsewhere
12
+ // cannot keep stale links into its former tree.
13
+ child.previousSibling = parent.lastChild ?? null
14
+ child.nextSibling = null
15
+
4
16
  if (parent.firstChild == null) {
5
17
  parent.firstChild = child
6
18
  }
7
19
 
8
20
  if (parent.lastChild) {
9
21
  parent.lastChild.nextSibling = child
10
- child.previousSibling = parent.lastChild
11
22
  }
12
23
 
13
24
  parent.lastChild = child
@@ -17,5 +17,11 @@ export function detachChild<T extends TreeNode<unknown>>(parent: T, child: T) {
17
17
  child.nextSibling.previousSibling = child.previousSibling ?? null
18
18
  }
19
19
 
20
+ // Detach the child's own links so it cannot reach back into the tree it
21
+ // was removed from.
22
+ child.parent = null
23
+ child.previousSibling = null
24
+ child.nextSibling = null
25
+
20
26
  return parent
21
27
  }