@remix-run/ui 0.7.0 → 0.9.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 (91) hide show
  1. package/README.md +90 -14
  2. package/dist/animation/demos/drag-release.js +5 -7
  3. package/dist/animation/demos/drag-release.js.map +1 -1
  4. package/dist/index.d.ts +2 -2
  5. package/dist/index.js +1 -1
  6. package/dist/index.js.map +1 -1
  7. package/dist/runtime/component.d.ts +9 -4
  8. package/dist/runtime/component.js +38 -9
  9. package/dist/runtime/component.js.map +1 -1
  10. package/dist/runtime/core/mix.d.ts +21 -0
  11. package/dist/runtime/core/mix.js +128 -0
  12. package/dist/runtime/core/mix.js.map +1 -0
  13. package/dist/runtime/diff-dom.js +15 -16
  14. package/dist/runtime/diff-dom.js.map +1 -1
  15. package/dist/runtime/document-reload.d.ts +2 -0
  16. package/dist/runtime/document-reload.js +14 -0
  17. package/dist/runtime/document-reload.js.map +1 -0
  18. package/dist/runtime/dom.d.ts +21 -11
  19. package/dist/runtime/event-types.d.ts +14 -0
  20. package/dist/runtime/event-types.js +2 -0
  21. package/dist/runtime/event-types.js.map +1 -0
  22. package/dist/runtime/frame-resolution.js +8 -0
  23. package/dist/runtime/frame-resolution.js.map +1 -1
  24. package/dist/runtime/frame.d.ts +24 -6
  25. package/dist/runtime/frame.js +187 -60
  26. package/dist/runtime/frame.js.map +1 -1
  27. package/dist/runtime/import-map-manager.d.ts +8 -0
  28. package/dist/runtime/import-map-manager.js +295 -0
  29. package/dist/runtime/import-map-manager.js.map +1 -0
  30. package/dist/runtime/mixins/link-mixin.js +4 -4
  31. package/dist/runtime/mixins/link-mixin.js.map +1 -1
  32. package/dist/runtime/mixins/mixin.d.ts +9 -4
  33. package/dist/runtime/mixins/mixin.js +18 -132
  34. package/dist/runtime/mixins/mixin.js.map +1 -1
  35. package/dist/runtime/mixins/on-mixin.d.ts +1 -1
  36. package/dist/runtime/module-preloader.d.ts +2 -1
  37. package/dist/runtime/module-preloader.js +6 -5
  38. package/dist/runtime/module-preloader.js.map +1 -1
  39. package/dist/runtime/navigation.js +211 -34
  40. package/dist/runtime/navigation.js.map +1 -1
  41. package/dist/runtime/reconcile.js +18 -3
  42. package/dist/runtime/reconcile.js.map +1 -1
  43. package/dist/runtime/run.d.ts +3 -0
  44. package/dist/runtime/run.js +8 -4
  45. package/dist/runtime/run.js.map +1 -1
  46. package/dist/runtime/scheduler.js +37 -11
  47. package/dist/runtime/scheduler.js.map +1 -1
  48. package/dist/runtime/spa-response.d.ts +30 -0
  49. package/dist/runtime/spa-response.js +47 -0
  50. package/dist/runtime/spa-response.js.map +1 -0
  51. package/dist/runtime/to-vnode.js +1 -1
  52. package/dist/runtime/to-vnode.js.map +1 -1
  53. package/dist/runtime/typed-event-target.d.ts +0 -4
  54. package/dist/runtime/typed-event-target.js.map +1 -1
  55. package/dist/server/stream.d.ts +25 -2
  56. package/dist/server/stream.js +382 -171
  57. package/dist/server/stream.js.map +1 -1
  58. package/dist/style/stylesheet.js +2 -2
  59. package/dist/style/stylesheet.js.map +1 -1
  60. package/package.json +1 -1
  61. package/src/animation/demos/drag-release.ts +5 -7
  62. package/src/index.ts +2 -2
  63. package/src/runtime/component.ts +52 -14
  64. package/src/runtime/core/mix.ts +157 -0
  65. package/src/runtime/demos/readme.demo.tsx +7 -17
  66. package/src/runtime/diff-dom.ts +13 -15
  67. package/src/runtime/document-reload.ts +14 -0
  68. package/src/runtime/dom.ts +21 -11
  69. package/src/runtime/event-types.ts +27 -0
  70. package/src/runtime/frame-resolution.ts +9 -0
  71. package/src/runtime/frame.ts +216 -65
  72. package/src/runtime/import-map-manager.ts +369 -0
  73. package/src/runtime/mixins/link-mixin.ts +4 -4
  74. package/src/runtime/mixins/mixin.ts +44 -149
  75. package/src/runtime/mixins/on-mixin.ts +1 -1
  76. package/src/runtime/module-preloader.ts +9 -6
  77. package/src/runtime/navigation.ts +257 -42
  78. package/src/runtime/reconcile.ts +20 -4
  79. package/src/runtime/run.ts +13 -4
  80. package/src/runtime/scheduler.ts +53 -13
  81. package/src/runtime/spa-response.ts +56 -0
  82. package/src/runtime/to-vnode.ts +1 -1
  83. package/src/runtime/typed-event-target.ts +1 -6
  84. package/src/server/README.md +25 -5
  85. package/src/server/stream.ts +506 -202
  86. package/src/style/stylesheet.ts +3 -3
  87. package/src/test/utils.ts +1 -6
  88. package/dist/runtime/event-listeners.d.ts +0 -50
  89. package/dist/runtime/event-listeners.js +0 -31
  90. package/dist/runtime/event-listeners.js.map +0 -1
  91. package/src/runtime/event-listeners.ts +0 -171
@@ -28,7 +28,7 @@ type BoundarySiblingUnit = {
28
28
 
29
29
  type SiblingUnit = NodeSiblingUnit | BoundarySiblingUnit
30
30
 
31
- const REMIX_PRESERVE_DOM_ATTRIBUTE = 'rmx-preserve-dom'
31
+ const REMIX_PRESERVE_DOM_ATTRIBUTE = 'data-rmx-preserve-dom'
32
32
 
33
33
  export function diffNodes(curr: Node[], next: Node[], context: FrameContext) {
34
34
  let parent = curr[0]?.parentNode ?? context.regionParent ?? null
@@ -80,14 +80,17 @@ function diffNode(current: Node, next: Node, context: FrameContext): ChildNode |
80
80
  if (nextMarkerData.status === 'resolved') {
81
81
  let nextEnd = findFrameEndMarker(next)
82
82
  let nextContent = collectFrameContentFragment(current.ownerDocument, next, nextEnd)
83
- void frame.renderMarkerContent(
83
+ let render = frame.renderMarkerContent(
84
84
  { ...nextMarkerData, id: getFrameId(next) },
85
85
  nextContent,
86
86
  {
87
87
  data: context.data,
88
88
  signal: context.signal,
89
+ reconciliationTracker: context.reconciliationTracker,
89
90
  },
90
91
  )
92
+ if (context.reconciliationTracker) context.reconciliationTracker.waitFor(render)
93
+ else void render
91
94
  return nextEnd
92
95
  }
93
96
 
@@ -237,20 +240,15 @@ function isPopoverOpen(element: Element): boolean {
237
240
  }
238
241
 
239
242
  function diffElementChildren(current: Element, next: Element, context: FrameContext): void {
240
- let currentChildren: Node[]
241
-
242
- // Allow actively managed preload link tags in the head to stay in the document
243
- // during diffing rather than removing them which aborts the preload in Safari
244
- if (context.isActiveModulePreload && current === current.ownerDocument.head) {
245
- currentChildren = []
246
- for (let node of current.childNodes) {
247
- if (!context.isActiveModulePreload(node)) currentChildren.push(node)
248
- }
249
- } else {
250
- currentChildren = Array.from(current.childNodes)
243
+ let shouldPreserveHeadNode = context.shouldPreserveHeadNode
244
+ let preservedHeadNodes: ChildNode[] = []
245
+ let currentChildren = Array.from(current.childNodes)
246
+ if (current === current.ownerDocument.head && shouldPreserveHeadNode) {
247
+ preservedHeadNodes = currentChildren.filter(shouldPreserveHeadNode)
248
+ currentChildren = currentChildren.filter((node) => !shouldPreserveHeadNode(node))
251
249
  }
252
250
  let nextChildren = Array.from(next.childNodes)
253
- diffSiblingUnits(currentChildren, nextChildren, current, null, context)
251
+ diffSiblingUnits(currentChildren, nextChildren, current, preservedHeadNodes[0] ?? null, context)
254
252
  }
255
253
 
256
254
  function diffSiblingUnits(
@@ -446,7 +444,7 @@ function parseSiblingUnits(nodes: Node[]): SiblingUnit[] {
446
444
 
447
445
  function getSiblingUnitKey(unit: SiblingUnit): string | undefined {
448
446
  if (unit.kind !== 'node' || !isElement(unit.node)) return
449
- return unit.node.getAttribute('data-key') ?? undefined
447
+ return unit.node.getAttribute('data-rmx-key') ?? undefined
450
448
  }
451
449
 
452
450
  function siblingUnitsComparable(current: SiblingUnit, next: SiblingUnit): boolean {
@@ -0,0 +1,14 @@
1
+ const documentReloadInfo = 'remix-document-reload'
2
+
3
+ export function isDocumentReload(info: unknown): boolean {
4
+ return info === documentReloadInfo
5
+ }
6
+
7
+ export function reloadDocument(doc: Document, href = doc.location.href): void {
8
+ let navigation = doc.defaultView?.navigation
9
+ if (navigation) {
10
+ navigation.navigate(href, { history: 'replace', info: documentReloadInfo })
11
+ } else {
12
+ doc.location.replace(href)
13
+ }
14
+ }
@@ -1561,10 +1561,10 @@ export interface AllHTMLProps<eventTarget extends EventTarget = EventTarget>
1561
1561
  * Preserve the current element attributes and children during frame DOM reconciliation.
1562
1562
  *
1563
1563
  * Server rendering and initial hydration still process this element and its children. On later
1564
- * frame reloads, a matched element with `rmx-preserve-dom` keeps its live DOM so custom elements
1565
- * and imperative widgets can own their subtree.
1564
+ * frame reloads, a matched element with `data-rmx-preserve-dom` keeps its live DOM so custom
1565
+ * elements and imperative widgets can own their subtree.
1566
1566
  */
1567
- 'rmx-preserve-dom'?: Trackable<boolean | '' | undefined>
1567
+ 'data-rmx-preserve-dom'?: Trackable<boolean | '' | undefined>
1568
1568
 
1569
1569
  // RDFa Attributes
1570
1570
  /** The `about` HTML attribute. */
@@ -1786,14 +1786,16 @@ export interface PartialAnchorHTMLProps<
1786
1786
  referrerPolicy?: Trackable<HTMLAttributeReferrerPolicy | undefined>
1787
1787
 
1788
1788
  // Non-standard Attributes
1789
- /** The `rmx-target` HTML attribute. */
1790
- 'rmx-target'?: Trackable<string | undefined>
1791
- /** The `rmx-src` HTML attribute. */
1792
- 'rmx-src'?: Trackable<string | undefined>
1789
+ /** The `data-rmx-document` HTML attribute. */
1790
+ 'data-rmx-document'?: Trackable<boolean | '' | undefined>
1791
+ /** The `data-rmx-target` HTML attribute. */
1792
+ 'data-rmx-target'?: Trackable<string | undefined>
1793
+ /** The `data-rmx-src` HTML attribute. */
1794
+ 'data-rmx-src'?: Trackable<string | undefined>
1793
1795
  /** Controls how activating this anchor updates the current history entry. */
1794
- 'rmx-history'?: Trackable<'push' | 'replace' | undefined>
1795
- /** The `rmx-reset-scroll` HTML attribute. */
1796
- 'rmx-reset-scroll'?: Trackable<string | undefined>
1796
+ 'data-rmx-history'?: Trackable<'push' | 'replace' | undefined>
1797
+ /** The `data-rmx-reset-scroll` HTML attribute. */
1798
+ 'data-rmx-reset-scroll'?: Trackable<string | undefined>
1797
1799
  }
1798
1800
 
1799
1801
  export type AnchorAriaRoles =
@@ -2297,8 +2299,16 @@ export interface FormHTMLProps<
2297
2299
  target?: Trackable<string | undefined>
2298
2300
 
2299
2301
  // Non-standard Attributes
2302
+ /** The `data-rmx-document` HTML attribute. */
2303
+ 'data-rmx-document'?: Trackable<boolean | '' | undefined>
2304
+ /** The `data-rmx-target` HTML attribute. */
2305
+ 'data-rmx-target'?: Trackable<string | undefined>
2306
+ /** The `data-rmx-src` HTML attribute. */
2307
+ 'data-rmx-src'?: Trackable<string | undefined>
2300
2308
  /** Overrides how submitting this form updates the current history entry. */
2301
- 'rmx-history'?: Trackable<'push' | 'replace' | undefined>
2309
+ 'data-rmx-history'?: Trackable<'push' | 'replace' | undefined>
2310
+ /** The `data-rmx-reset-scroll` HTML attribute. */
2311
+ 'data-rmx-reset-scroll'?: Trackable<string | undefined>
2302
2312
  }
2303
2313
 
2304
2314
  /**
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Event type with `currentTarget` narrowed to the dispatched target.
3
+ */
4
+ export type Dispatched<event extends Event, target extends EventTarget> = Omit<
5
+ event,
6
+ 'currentTarget'
7
+ > & {
8
+ currentTarget: target
9
+ }
10
+
11
+ /**
12
+ * Narrows non-event values to `never` and preserves dispatched event typing otherwise.
13
+ */
14
+ export type EnsureEvent<event, target extends EventTarget> = event extends Event
15
+ ? Dispatched<event, target>
16
+ : never
17
+
18
+ /**
19
+ * Event map resolved for a DOM element.
20
+ */
21
+ export type EventMap<target extends Element> = target extends HTMLElement
22
+ ? HTMLElementEventMap
23
+ : target extends SVGSVGElement
24
+ ? SVGSVGElementEventMap
25
+ : target extends SVGElement
26
+ ? SVGElementEventMap
27
+ : ElementEventMap
@@ -1,10 +1,19 @@
1
1
  import type { FrameContent, FrameResolution } from './component.ts'
2
+ import { getSpaResponseData } from './spa-response.ts'
2
3
 
3
4
  export async function unwrapFrameResolution(
4
5
  resolution: FrameResolution,
5
6
  ): Promise<{ content: FrameContent; redirectedTo?: string }> {
6
7
  if (!(resolution instanceof Response)) return { content: resolution }
7
8
 
9
+ let data = getSpaResponseData(resolution)
10
+ if (data) {
11
+ return {
12
+ content: data.node,
13
+ redirectedTo: data.redirectedTo,
14
+ }
15
+ }
16
+
8
17
  let content = resolution.body ?? (await resolution.text())
9
18
  return {
10
19
  content,