@ventually/ui 0.0.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.
- package/README.md +51 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +163 -0
- package/dist/context.d.ts +20 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +76 -0
- package/dist/context.test.d.ts +2 -0
- package/dist/context.test.d.ts.map +1 -0
- package/dist/context.test.js +26 -0
- package/dist/dashboard.d.ts +3 -0
- package/dist/dashboard.d.ts.map +1 -0
- package/dist/dashboard.js +273 -0
- package/dist/index.cjs +15 -0
- package/dist/index.css +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/runtime.d.ts +47 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +303 -0
- package/dist/shared-types.d.ts +71 -0
- package/dist/shared-types.d.ts.map +1 -0
- package/dist/shared-types.js +1 -0
- package/dist/standalone/assets/index-BM0MHT5H.js +18 -0
- package/dist/standalone/assets/index-CvxuexK-.css +1 -0
- package/dist/standalone/index.html +13 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/package.json +59 -0
- package/src/cli.ts +215 -0
- package/src/context.test.tsx +47 -0
- package/src/context.tsx +130 -0
- package/src/dashboard.tsx +835 -0
- package/src/index.css +1 -0
- package/src/index.ts +11 -0
- package/src/runtime.ts +414 -0
- package/src/shared-types.ts +67 -0
- package/src/standalone/App.tsx +31 -0
- package/src/standalone/index.html +12 -0
- package/src/standalone/main.tsx +10 -0
- package/src/types.ts +9 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@layer theme{:root,:host{--font-sans:ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";--font-mono:ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;--default-font-family:var(--font-sans);--default-mono-font-family:var(--font-mono)}}@layer base{*,:after,:before,::backdrop{box-sizing:border-box;border:0 solid;margin:0;padding:0}::file-selector-button{box-sizing:border-box;border:0 solid;margin:0;padding:0}html,:host{-webkit-text-size-adjust:100%;tab-size:4;line-height:1.5;font-family:var(--default-font-family,ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji");font-feature-settings:var(--default-font-feature-settings,normal);font-variation-settings:var(--default-font-variation-settings,normal);-webkit-tap-highlight-color:transparent}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;-webkit-text-decoration:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:var(--default-mono-font-family,ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace);font-feature-settings:var(--default-mono-font-feature-settings,normal);font-variation-settings:var(--default-mono-font-variation-settings,normal);font-size:1em}small{font-size:80%}sub,sup{vertical-align:baseline;font-size:75%;line-height:0;position:relative}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}:-moz-focusring{outline:auto}progress{vertical-align:baseline}summary{display:list-item}ol,ul,menu{list-style:none}img,svg,video,canvas,audio,iframe,embed,object{vertical-align:middle;display:block}img,video{max-width:100%;height:auto}button,input,select,optgroup,textarea{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}::file-selector-button{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}:where(select:is([multiple],[size])) optgroup{font-weight:bolder}:where(select:is([multiple],[size])) optgroup option{padding-inline-start:20px}::file-selector-button{margin-inline-end:4px}::placeholder{opacity:1}@supports (not ((-webkit-appearance:-apple-pay-button))) or (contain-intrinsic-size:1px){::placeholder{color:currentColor}@supports (color:color-mix(in lab,red,red)){::placeholder{color:color-mix(in oklab,currentcolor 50%,transparent)}}}textarea{resize:vertical}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-date-and-time-value{min-height:1lh;text-align:inherit}::-webkit-datetime-edit{display:inline-flex}::-webkit-datetime-edit-fields-wrapper{padding:0}::-webkit-datetime-edit{padding-block:0}::-webkit-datetime-edit-year-field{padding-block:0}::-webkit-datetime-edit-month-field{padding-block:0}::-webkit-datetime-edit-day-field{padding-block:0}::-webkit-datetime-edit-hour-field{padding-block:0}::-webkit-datetime-edit-minute-field{padding-block:0}::-webkit-datetime-edit-second-field{padding-block:0}::-webkit-datetime-edit-millisecond-field{padding-block:0}::-webkit-datetime-edit-meridiem-field{padding-block:0}::-webkit-calendar-picker-indicator{line-height:1}:-moz-ui-invalid{box-shadow:none}button,input:where([type=button],[type=reset],[type=submit]){appearance:button}::file-selector-button{appearance:button}::-webkit-inner-spin-button{height:auto}::-webkit-outer-spin-button{height:auto}[hidden]:where(:not([hidden=until-found])){display:none!important}}@layer components,utilities;@layer properties{@supports (((-webkit-hyphens:none)) and (not (margin-trim:inline))) or ((-moz-orient:inline) and (not (color:rgb(from red r g b)))){*,:before,:after,::backdrop{--tw-space-y-reverse:0;--tw-divide-x-reverse:0;--tw-border-style:solid;--tw-divide-y-reverse:0;--tw-leading:initial;--tw-font-weight:initial;--tw-tracking:initial;--tw-shadow:0 0 #0000;--tw-shadow-color:initial;--tw-shadow-alpha:100%;--tw-inset-shadow:0 0 #0000;--tw-inset-shadow-color:initial;--tw-inset-shadow-alpha:100%;--tw-ring-color:initial;--tw-ring-shadow:0 0 #0000;--tw-inset-ring-color:initial;--tw-inset-ring-shadow:0 0 #0000;--tw-ring-inset:initial;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-offset-shadow:0 0 #0000;--tw-duration:initial}}}@layer theme{:root,:host{--font-sans:ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";--font-mono:ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;--color-red-400:oklch(70.4% .191 22.216);--color-red-500:oklch(63.7% .237 25.331);--color-amber-400:oklch(82.8% .189 84.429);--color-emerald-400:oklch(76.5% .177 163.223);--color-blue-400:oklch(70.7% .165 254.624);--color-violet-400:oklch(70.2% .183 293.541);--color-zinc-100:oklch(96.7% .001 286.375);--color-zinc-200:oklch(92% .004 286.32);--color-zinc-300:oklch(87.1% .006 286.286);--color-zinc-400:oklch(70.5% .015 286.067);--color-zinc-500:oklch(55.2% .016 285.938);--color-zinc-600:oklch(44.2% .017 285.786);--color-zinc-700:oklch(37% .013 285.805);--color-zinc-800:oklch(27.4% .006 286.033);--color-zinc-900:oklch(21% .006 285.885);--color-zinc-950:oklch(14.1% .005 285.823);--color-white:#fff;--spacing:.25rem;--container-xs:20rem;--container-md:28rem;--container-lg:32rem;--text-xs:.75rem;--text-xs--line-height:calc(1 / .75);--text-sm:.875rem;--text-sm--line-height:calc(1.25 / .875);--text-2xl:1.5rem;--text-2xl--line-height:calc(2 / 1.5);--font-weight-medium:500;--font-weight-semibold:600;--tracking-wide:.025em;--tracking-wider:.05em;--leading-relaxed:1.625;--radius-sm:.25rem;--radius-lg:.5rem;--radius-xl:.75rem;--animate-pulse:pulse 2s cubic-bezier(.4, 0, .6, 1) infinite;--default-transition-duration:.15s;--default-transition-timing-function:cubic-bezier(.4, 0, .2, 1);--default-font-family:var(--font-sans);--default-mono-font-family:var(--font-mono)}}@layer base{*,:after,:before,::backdrop{box-sizing:border-box;border:0 solid;margin:0;padding:0}::file-selector-button{box-sizing:border-box;border:0 solid;margin:0;padding:0}html,:host{-webkit-text-size-adjust:100%;tab-size:4;line-height:1.5;font-family:var(--default-font-family,ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji");font-feature-settings:var(--default-font-feature-settings,normal);font-variation-settings:var(--default-font-variation-settings,normal);-webkit-tap-highlight-color:transparent}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;-webkit-text-decoration:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:var(--default-mono-font-family,ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace);font-feature-settings:var(--default-mono-font-feature-settings,normal);font-variation-settings:var(--default-mono-font-variation-settings,normal);font-size:1em}small{font-size:80%}sub,sup{vertical-align:baseline;font-size:75%;line-height:0;position:relative}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}:-moz-focusring{outline:auto}progress{vertical-align:baseline}summary{display:list-item}ol,ul,menu{list-style:none}img,svg,video,canvas,audio,iframe,embed,object{vertical-align:middle;display:block}img,video{max-width:100%;height:auto}button,input,select,optgroup,textarea{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}::file-selector-button{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}:where(select:is([multiple],[size])) optgroup{font-weight:bolder}:where(select:is([multiple],[size])) optgroup option{padding-inline-start:20px}::file-selector-button{margin-inline-end:4px}::placeholder{opacity:1}@supports (not ((-webkit-appearance:-apple-pay-button))) or (contain-intrinsic-size:1px){::placeholder{color:currentColor}@supports (color:color-mix(in lab,red,red)){::placeholder{color:color-mix(in oklab,currentcolor 50%,transparent)}}}textarea{resize:vertical}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-date-and-time-value{min-height:1lh;text-align:inherit}::-webkit-datetime-edit{display:inline-flex}::-webkit-datetime-edit-fields-wrapper{padding:0}::-webkit-datetime-edit{padding-block:0}::-webkit-datetime-edit-year-field{padding-block:0}::-webkit-datetime-edit-month-field{padding-block:0}::-webkit-datetime-edit-day-field{padding-block:0}::-webkit-datetime-edit-hour-field{padding-block:0}::-webkit-datetime-edit-minute-field{padding-block:0}::-webkit-datetime-edit-second-field{padding-block:0}::-webkit-datetime-edit-millisecond-field{padding-block:0}::-webkit-datetime-edit-meridiem-field{padding-block:0}::-webkit-calendar-picker-indicator{line-height:1}:-moz-ui-invalid{box-shadow:none}button,input:where([type=button],[type=reset],[type=submit]){appearance:button}::file-selector-button{appearance:button}::-webkit-inner-spin-button{height:auto}::-webkit-outer-spin-button{height:auto}[hidden]:where(:not([hidden=until-found])){display:none!important}}@layer components;@layer utilities{.pointer-events-none{pointer-events:none}.absolute{position:absolute}.fixed{position:fixed}.relative{position:relative}.inset-0{inset:calc(var(--spacing) * 0)}.start{inset-inline-start:var(--spacing)}.z-10{z-index:10}.z-50{z-index:50}.col-span-2{grid-column:span 2/span 2}.mt-3{margin-top:calc(var(--spacing) * 3)}.mb-0\.5{margin-bottom:calc(var(--spacing) * .5)}.mb-1\.5{margin-bottom:calc(var(--spacing) * 1.5)}.mb-2{margin-bottom:calc(var(--spacing) * 2)}.mb-3{margin-bottom:calc(var(--spacing) * 3)}.mb-5{margin-bottom:calc(var(--spacing) * 5)}.ml-auto{margin-left:auto}.flex{display:flex}.grid{display:grid}.hidden{display:none}.inline-flex{display:inline-flex}.table{display:table}.h-1\.5{height:calc(var(--spacing) * 1.5)}.h-2{height:calc(var(--spacing) * 2)}.h-3{height:calc(var(--spacing) * 3)}.h-6{height:calc(var(--spacing) * 6)}.h-7{height:calc(var(--spacing) * 7)}.h-10{height:calc(var(--spacing) * 10)}.h-12{height:calc(var(--spacing) * 12)}.h-44{height:calc(var(--spacing) * 44)}.h-\[calc\(100\%-0\.75rem\)\]{height:calc(100% - .75rem)}.h-full{height:100%}.h-px{height:1px}.h-screen{height:100vh}.min-h-0{min-height:calc(var(--spacing) * 0)}.w-0{width:calc(var(--spacing) * 0)}.w-1\.5{width:calc(var(--spacing) * 1.5)}.w-2{width:calc(var(--spacing) * 2)}.w-6{width:calc(var(--spacing) * 6)}.w-7{width:calc(var(--spacing) * 7)}.w-10{width:calc(var(--spacing) * 10)}.w-52{width:calc(var(--spacing) * 52)}.w-full{width:100%}.max-w-lg{max-width:var(--container-lg)}.max-w-md{max-width:var(--container-md)}.max-w-xs{max-width:var(--container-xs)}.min-w-0{min-width:calc(var(--spacing) * 0)}.flex-1{flex:1}.flex-shrink-0{flex-shrink:0}.animate-pulse{animation:var(--animate-pulse)}.touch-none{touch-action:none}.resize-y{resize:vertical}.grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.grid-cols-5{grid-template-columns:repeat(5,minmax(0,1fr))}.flex-col{flex-direction:column}.items-center{align-items:center}.items-end{align-items:flex-end}.justify-between{justify-content:space-between}.justify-center{justify-content:center}.justify-end{justify-content:flex-end}.gap-0\.5{gap:calc(var(--spacing) * .5)}.gap-1{gap:calc(var(--spacing) * 1)}.gap-1\.5{gap:calc(var(--spacing) * 1.5)}.gap-2{gap:calc(var(--spacing) * 2)}.gap-2\.5{gap:calc(var(--spacing) * 2.5)}.gap-3{gap:calc(var(--spacing) * 3)}:where(.space-y-3>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing) * 3) * var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing) * 3) * calc(1 - var(--tw-space-y-reverse)))}:where(.divide-x>:not(:last-child)){--tw-divide-x-reverse:0;border-inline-style:var(--tw-border-style);border-inline-start-width:calc(1px * var(--tw-divide-x-reverse));border-inline-end-width:calc(1px * calc(1 - var(--tw-divide-x-reverse)))}:where(.divide-y>:not(:last-child)){--tw-divide-y-reverse:0;border-bottom-style:var(--tw-border-style);border-top-style:var(--tw-border-style);border-top-width:calc(1px * var(--tw-divide-y-reverse));border-bottom-width:calc(1px * calc(1 - var(--tw-divide-y-reverse)))}:where(.divide-zinc-800\/40>:not(:last-child)){border-color:#27272a66}@supports (color:color-mix(in lab,red,red)){:where(.divide-zinc-800\/40>:not(:last-child)){border-color:color-mix(in oklab,var(--color-zinc-800) 40%,transparent)}}:where(.divide-zinc-800\/60>:not(:last-child)){border-color:#27272a99}@supports (color:color-mix(in lab,red,red)){:where(.divide-zinc-800\/60>:not(:last-child)){border-color:color-mix(in oklab,var(--color-zinc-800) 60%,transparent)}}.truncate{text-overflow:ellipsis;white-space:nowrap;overflow:hidden}.overflow-auto{overflow:auto}.overflow-hidden{overflow:hidden}.overflow-y-auto{overflow-y:auto}.rounded{border-radius:.25rem}.rounded-full{border-radius:3.40282e38px}.rounded-lg{border-radius:var(--radius-lg)}.rounded-sm{border-radius:var(--radius-sm)}.rounded-xl{border-radius:var(--radius-xl)}.border{border-style:var(--tw-border-style);border-width:1px}.border-t{border-top-style:var(--tw-border-style);border-top-width:1px}.border-r{border-right-style:var(--tw-border-style);border-right-width:1px}.border-b{border-bottom-style:var(--tw-border-style);border-bottom-width:1px}.border-red-400\/20{border-color:#ff656833}@supports (color:color-mix(in lab,red,red)){.border-red-400\/20{border-color:color-mix(in oklab,var(--color-red-400) 20%,transparent)}}.border-zinc-700{border-color:var(--color-zinc-700)}.border-zinc-800{border-color:var(--color-zinc-800)}.border-zinc-800\/60{border-color:#27272a99}@supports (color:color-mix(in lab,red,red)){.border-zinc-800\/60{border-color:color-mix(in oklab,var(--color-zinc-800) 60%,transparent)}}.bg-amber-400{background-color:var(--color-amber-400)}.bg-amber-400\/10{background-color:#fcbb001a}@supports (color:color-mix(in lab,red,red)){.bg-amber-400\/10{background-color:color-mix(in oklab,var(--color-amber-400) 10%,transparent)}}.bg-blue-400{background-color:var(--color-blue-400)}.bg-blue-400\/10{background-color:#54a2ff1a}@supports (color:color-mix(in lab,red,red)){.bg-blue-400\/10{background-color:color-mix(in oklab,var(--color-blue-400) 10%,transparent)}}.bg-emerald-400{background-color:var(--color-emerald-400)}.bg-emerald-400\/10{background-color:#00d2941a}@supports (color:color-mix(in lab,red,red)){.bg-emerald-400\/10{background-color:color-mix(in oklab,var(--color-emerald-400) 10%,transparent)}}.bg-red-400{background-color:var(--color-red-400)}.bg-red-400\/8{background-color:#ff656814}@supports (color:color-mix(in lab,red,red)){.bg-red-400\/8{background-color:color-mix(in oklab,var(--color-red-400) 8%,transparent)}}.bg-red-400\/10{background-color:#ff65681a}@supports (color:color-mix(in lab,red,red)){.bg-red-400\/10{background-color:color-mix(in oklab,var(--color-red-400) 10%,transparent)}}.bg-violet-400{background-color:var(--color-violet-400)}.bg-violet-400\/10{background-color:#a685ff1a}@supports (color:color-mix(in lab,red,red)){.bg-violet-400\/10{background-color:color-mix(in oklab,var(--color-violet-400) 10%,transparent)}}.bg-zinc-100{background-color:var(--color-zinc-100)}.bg-zinc-700{background-color:var(--color-zinc-700)}.bg-zinc-800{background-color:var(--color-zinc-800)}.bg-zinc-800\/50{background-color:#27272a80}@supports (color:color-mix(in lab,red,red)){.bg-zinc-800\/50{background-color:color-mix(in oklab,var(--color-zinc-800) 50%,transparent)}}.bg-zinc-800\/60{background-color:#27272a99}@supports (color:color-mix(in lab,red,red)){.bg-zinc-800\/60{background-color:color-mix(in oklab,var(--color-zinc-800) 60%,transparent)}}.bg-zinc-900{background-color:var(--color-zinc-900)}.bg-zinc-950{background-color:var(--color-zinc-950)}.p-3{padding:calc(var(--spacing) * 3)}.p-4{padding:calc(var(--spacing) * 4)}.p-5{padding:calc(var(--spacing) * 5)}.px-0{padding-inline:calc(var(--spacing) * 0)}.px-1{padding-inline:calc(var(--spacing) * 1)}.px-2{padding-inline:calc(var(--spacing) * 2)}.px-3{padding-inline:calc(var(--spacing) * 3)}.px-4{padding-inline:calc(var(--spacing) * 4)}.px-5{padding-inline:calc(var(--spacing) * 5)}.px-8{padding-inline:calc(var(--spacing) * 8)}.py-0\.5{padding-block:calc(var(--spacing) * .5)}.py-1\.5{padding-block:calc(var(--spacing) * 1.5)}.py-2{padding-block:calc(var(--spacing) * 2)}.py-2\.5{padding-block:calc(var(--spacing) * 2.5)}.py-3{padding-block:calc(var(--spacing) * 3)}.py-4{padding-block:calc(var(--spacing) * 4)}.py-5{padding-block:calc(var(--spacing) * 5)}.py-10{padding-block:calc(var(--spacing) * 10)}.py-16{padding-block:calc(var(--spacing) * 16)}.pt-1{padding-top:calc(var(--spacing) * 1)}.pt-4{padding-top:calc(var(--spacing) * 4)}.pt-5{padding-top:calc(var(--spacing) * 5)}.pr-1{padding-right:calc(var(--spacing) * 1)}.pb-2{padding-bottom:calc(var(--spacing) * 2)}.pb-4{padding-bottom:calc(var(--spacing) * 4)}.text-center{text-align:center}.text-left{text-align:left}.font-mono{font-family:var(--font-mono)}.text-2xl{font-size:var(--text-2xl);line-height:var(--tw-leading,var(--text-2xl--line-height))}.text-sm{font-size:var(--text-sm);line-height:var(--tw-leading,var(--text-sm--line-height))}.text-xs{font-size:var(--text-xs);line-height:var(--tw-leading,var(--text-xs--line-height))}.text-\[9px\]{font-size:9px}.text-\[10px\]{font-size:10px}.text-\[11px\]{font-size:11px}.leading-none{--tw-leading:1;line-height:1}.leading-relaxed{--tw-leading:var(--leading-relaxed);line-height:var(--leading-relaxed)}.font-medium{--tw-font-weight:var(--font-weight-medium);font-weight:var(--font-weight-medium)}.font-semibold{--tw-font-weight:var(--font-weight-semibold);font-weight:var(--font-weight-semibold)}.tracking-\[0\.12em\]{--tw-tracking:.12em;letter-spacing:.12em}.tracking-\[0\.14em\]{--tw-tracking:.14em;letter-spacing:.14em}.tracking-wide{--tw-tracking:var(--tracking-wide);letter-spacing:var(--tracking-wide)}.tracking-wider{--tw-tracking:var(--tracking-wider);letter-spacing:var(--tracking-wider)}.whitespace-nowrap{white-space:nowrap}.text-amber-400{color:var(--color-amber-400)}.text-blue-400{color:var(--color-blue-400)}.text-emerald-400{color:var(--color-emerald-400)}.text-red-400{color:var(--color-red-400)}.text-red-500\/70{color:#fb2c36b3}@supports (color:color-mix(in lab,red,red)){.text-red-500\/70{color:color-mix(in oklab,var(--color-red-500) 70%,transparent)}}.text-violet-400{color:var(--color-violet-400)}.text-zinc-100{color:var(--color-zinc-100)}.text-zinc-200{color:var(--color-zinc-200)}.text-zinc-300{color:var(--color-zinc-300)}.text-zinc-400{color:var(--color-zinc-400)}.text-zinc-500{color:var(--color-zinc-500)}.text-zinc-600{color:var(--color-zinc-600)}.text-zinc-700{color:var(--color-zinc-700)}.text-zinc-900{color:var(--color-zinc-900)}.uppercase{text-transform:uppercase}.opacity-0{opacity:0}.opacity-100{opacity:1}.shadow-2xl{--tw-shadow:0 25px 50px -12px var(--tw-shadow-color,#00000040);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.ring-1{--tw-ring-shadow:var(--tw-ring-inset,) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color,currentcolor);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.ring-amber-400\/25{--tw-ring-color:#fcbb0040}@supports (color:color-mix(in lab,red,red)){.ring-amber-400\/25{--tw-ring-color:color-mix(in oklab, var(--color-amber-400) 25%, transparent)}}.ring-blue-400\/25{--tw-ring-color:#54a2ff40}@supports (color:color-mix(in lab,red,red)){.ring-blue-400\/25{--tw-ring-color:color-mix(in oklab, var(--color-blue-400) 25%, transparent)}}.ring-emerald-400\/25{--tw-ring-color:#00d29440}@supports (color:color-mix(in lab,red,red)){.ring-emerald-400\/25{--tw-ring-color:color-mix(in oklab, var(--color-emerald-400) 25%, transparent)}}.ring-red-400\/25{--tw-ring-color:#ff656840}@supports (color:color-mix(in lab,red,red)){.ring-red-400\/25{--tw-ring-color:color-mix(in oklab, var(--color-red-400) 25%, transparent)}}.ring-violet-400\/25{--tw-ring-color:#a685ff40}@supports (color:color-mix(in lab,red,red)){.ring-violet-400\/25{--tw-ring-color:color-mix(in oklab, var(--color-violet-400) 25%, transparent)}}.transition-all{transition-property:all;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.transition-colors{transition-property:color,background-color,border-color,outline-color,text-decoration-color,fill,stroke,--tw-gradient-from,--tw-gradient-via,--tw-gradient-to;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.transition-opacity{transition-property:opacity;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.duration-150{--tw-duration:.15s;transition-duration:.15s}.duration-200{--tw-duration:.2s;transition-duration:.2s}.outline-none{--tw-outline-style:none;outline-style:none}@media(hover:hover){.group-hover\:bg-zinc-700:is(:where(.group):hover *){background-color:var(--color-zinc-700)}.group-hover\:opacity-100:is(:where(.group):hover *){opacity:1}.hover\:border-zinc-600:hover{border-color:var(--color-zinc-600)}.hover\:border-zinc-700:hover{border-color:var(--color-zinc-700)}.hover\:bg-white:hover{background-color:var(--color-white)}.hover\:bg-zinc-700:hover{background-color:var(--color-zinc-700)}.hover\:bg-zinc-800:hover{background-color:var(--color-zinc-800)}.hover\:bg-zinc-900:hover{background-color:var(--color-zinc-900)}.hover\:bg-zinc-900\/50:hover{background-color:#18181b80}@supports (color:color-mix(in lab,red,red)){.hover\:bg-zinc-900\/50:hover{background-color:color-mix(in oklab,var(--color-zinc-900) 50%,transparent)}}.hover\:text-zinc-200:hover{color:var(--color-zinc-200)}.hover\:text-zinc-300:hover{color:var(--color-zinc-300)}}.focus\:border-zinc-600:focus{border-color:var(--color-zinc-600)}.disabled\:opacity-40:disabled{opacity:.4}@media(min-width:48rem){.md\:flex{display:flex}.md\:w-12{width:calc(var(--spacing) * 12)}.md\:opacity-0{opacity:0}}@media(min-width:64rem){.lg\:block{display:block}}}@property --tw-space-y-reverse{syntax:"*";inherits:false;initial-value:0}@property --tw-divide-x-reverse{syntax:"*";inherits:false;initial-value:0}@property --tw-border-style{syntax:"*";inherits:false;initial-value:solid}@property --tw-divide-y-reverse{syntax:"*";inherits:false;initial-value:0}@property --tw-leading{syntax:"*";inherits:false}@property --tw-font-weight{syntax:"*";inherits:false}@property --tw-tracking{syntax:"*";inherits:false}@property --tw-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-shadow-color{syntax:"*";inherits:false}@property --tw-shadow-alpha{syntax:"<percentage>";inherits:false;initial-value:100%}@property --tw-inset-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-inset-shadow-color{syntax:"*";inherits:false}@property --tw-inset-shadow-alpha{syntax:"<percentage>";inherits:false;initial-value:100%}@property --tw-ring-color{syntax:"*";inherits:false}@property --tw-ring-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-inset-ring-color{syntax:"*";inherits:false}@property --tw-inset-ring-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-ring-inset{syntax:"*";inherits:false}@property --tw-ring-offset-width{syntax:"<length>";inherits:false;initial-value:0}@property --tw-ring-offset-color{syntax:"*";inherits:false;initial-value:#fff}@property --tw-ring-offset-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-duration{syntax:"*";inherits:false}@keyframes pulse{50%{opacity:.5}}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>@ventually/ui</title>
|
|
7
|
+
<script type="module" crossorigin src="/assets/index-BM0MHT5H.js"></script>
|
|
8
|
+
<link rel="stylesheet" crossorigin href="/assets/index-CvxuexK-.css">
|
|
9
|
+
</head>
|
|
10
|
+
<body style="margin:0">
|
|
11
|
+
<div id="root"></div>
|
|
12
|
+
</body>
|
|
13
|
+
</html>
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EACf,oBAAoB,EACpB,yBAAyB,EACzB,oBAAoB,EACpB,kBAAkB,GACnB,MAAM,mBAAmB,CAAC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ventually/ui",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"bin": {
|
|
6
|
+
"@ventually/ui": "./dist/cli.js"
|
|
7
|
+
},
|
|
8
|
+
"main": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./shared-types": {
|
|
16
|
+
"types": "./dist/shared-types.d.ts",
|
|
17
|
+
"default": "./dist/shared-types.js"
|
|
18
|
+
},
|
|
19
|
+
"./styles.css": "./dist/index.css"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"src"
|
|
24
|
+
],
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "rm -rf dist && vite build --config vite.config.ts && vite build --config vite.standalone.config.ts && tsc -p tsconfig.build.json",
|
|
30
|
+
"build:standalone": "vite build --config vite.standalone.config.ts",
|
|
31
|
+
"check-types": "tsc --noEmit -p tsconfig.json",
|
|
32
|
+
"dev": "vite --config vite.standalone.config.ts",
|
|
33
|
+
"start": "node ./dist/cli.js start"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@ventually/memory": "*",
|
|
37
|
+
"@tailwindcss/vite": "^4.2.2",
|
|
38
|
+
"@vitejs/plugin-react": "^5.1.0",
|
|
39
|
+
"@ventually/core": "*",
|
|
40
|
+
"tailwindcss": "^4.2.2",
|
|
41
|
+
"vite": "^7.1.9"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@repo/typescript-config": "*",
|
|
45
|
+
"@testing-library/react": "^16.3.0",
|
|
46
|
+
"@types/node": "^22.15.3",
|
|
47
|
+
"@types/react": "19.2.2",
|
|
48
|
+
"@types/react-dom": "19.2.2",
|
|
49
|
+
"jsdom": "^27.0.0",
|
|
50
|
+
"react": "^19.2.0",
|
|
51
|
+
"react-dom": "^19.2.0",
|
|
52
|
+
"typescript": "5.9.2",
|
|
53
|
+
"vite-plugin-css-injected-by-js": "^4.0.1"
|
|
54
|
+
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"react": "^18.3.0 || ^19.0.0",
|
|
57
|
+
"react-dom": "^18.3.0 || ^19.0.0"
|
|
58
|
+
}
|
|
59
|
+
}
|
package/src/cli.ts
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { createReadStream } from "node:fs";
|
|
4
|
+
import { access, readFile, stat } from "node:fs/promises";
|
|
5
|
+
import { createServer as createHttpServer } from "node:http";
|
|
6
|
+
import { dirname, extname, relative, resolve, sep } from "node:path";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
|
|
9
|
+
const DEFAULT_HOST = "127.0.0.1";
|
|
10
|
+
const DEFAULT_PORT = 3210;
|
|
11
|
+
const DEFAULT_ENDPOINT = "/api/playground";
|
|
12
|
+
|
|
13
|
+
const CONTENT_TYPES: Record<string, string> = {
|
|
14
|
+
".css": "text/css; charset=utf-8",
|
|
15
|
+
".html": "text/html; charset=utf-8",
|
|
16
|
+
".ico": "image/x-icon",
|
|
17
|
+
".jpeg": "image/jpeg",
|
|
18
|
+
".jpg": "image/jpeg",
|
|
19
|
+
".js": "text/javascript; charset=utf-8",
|
|
20
|
+
".json": "application/json; charset=utf-8",
|
|
21
|
+
".map": "application/json; charset=utf-8",
|
|
22
|
+
".png": "image/png",
|
|
23
|
+
".svg": "image/svg+xml",
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
async function main() {
|
|
27
|
+
const command = process.argv[2] ?? "start";
|
|
28
|
+
if (command !== "start") {
|
|
29
|
+
console.error(`Unsupported command: ${command}`);
|
|
30
|
+
process.exit(1);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const port = readFlagValue("--port")
|
|
34
|
+
? Number(readFlagValue("--port"))
|
|
35
|
+
: DEFAULT_PORT;
|
|
36
|
+
const host = readFlagValue("--host") ?? DEFAULT_HOST;
|
|
37
|
+
const endpoint = readFlagValue("--endpoint") ?? DEFAULT_ENDPOINT;
|
|
38
|
+
|
|
39
|
+
const packageRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
40
|
+
const standaloneRoot = resolve(packageRoot, "dist/standalone");
|
|
41
|
+
const standaloneIndexPath = resolve(standaloneRoot, "index.html");
|
|
42
|
+
|
|
43
|
+
await assertStandaloneBuildArtifacts(standaloneRoot, standaloneIndexPath);
|
|
44
|
+
|
|
45
|
+
const server = createHttpServer(async (request, response) => {
|
|
46
|
+
if (!request.url) {
|
|
47
|
+
response.statusCode = 400;
|
|
48
|
+
response.end("Missing URL");
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const requestPathname = readPathname(request.url);
|
|
53
|
+
if (!requestPathname) {
|
|
54
|
+
response.statusCode = 400;
|
|
55
|
+
response.end("Invalid URL");
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (requestPathname.startsWith("/api/")) {
|
|
60
|
+
response.statusCode = 404;
|
|
61
|
+
response.end("Not found");
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
await serveStandaloneAsset(request.url, response, {
|
|
66
|
+
endpoint,
|
|
67
|
+
standaloneRoot,
|
|
68
|
+
standaloneIndexPath,
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
server.listen(port, host, () => {
|
|
73
|
+
console.log(
|
|
74
|
+
`@ventually/ui listening on http://${host}:${port} (endpoint: ${endpoint})`,
|
|
75
|
+
);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async function assertStandaloneBuildArtifacts(
|
|
80
|
+
standaloneRoot: string,
|
|
81
|
+
standaloneIndexPath: string,
|
|
82
|
+
): Promise<void> {
|
|
83
|
+
try {
|
|
84
|
+
const [rootStats, indexStats] = await Promise.all([
|
|
85
|
+
stat(standaloneRoot),
|
|
86
|
+
stat(standaloneIndexPath),
|
|
87
|
+
]);
|
|
88
|
+
|
|
89
|
+
if (!rootStats.isDirectory() || !indexStats.isFile()) {
|
|
90
|
+
throw new Error("Standalone build artifacts missing");
|
|
91
|
+
}
|
|
92
|
+
} catch {
|
|
93
|
+
console.error(
|
|
94
|
+
`@ventually/ui standalone build artifacts not found at ${standaloneRoot}.\nRun \`bun --filter @ventually/ui build:standalone\` and try again.`,
|
|
95
|
+
);
|
|
96
|
+
process.exit(1);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async function serveStandaloneAsset(
|
|
101
|
+
rawUrl: string,
|
|
102
|
+
response: import("node:http").ServerResponse,
|
|
103
|
+
paths: {
|
|
104
|
+
endpoint: string;
|
|
105
|
+
standaloneRoot: string;
|
|
106
|
+
standaloneIndexPath: string;
|
|
107
|
+
},
|
|
108
|
+
): Promise<void> {
|
|
109
|
+
const pathname = readPathname(rawUrl);
|
|
110
|
+
if (!pathname) {
|
|
111
|
+
response.statusCode = 400;
|
|
112
|
+
response.end("Invalid URL");
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const requestedPath =
|
|
117
|
+
pathname === "/" ? paths.standaloneIndexPath : resolve(paths.standaloneRoot, `.${pathname}`);
|
|
118
|
+
|
|
119
|
+
if (!isPathInsideRoot(paths.standaloneRoot, requestedPath)) {
|
|
120
|
+
response.statusCode = 404;
|
|
121
|
+
response.end("Not found");
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const requestedStats = await safeStat(requestedPath);
|
|
126
|
+
if (requestedStats?.isFile()) {
|
|
127
|
+
if (requestedPath === paths.standaloneIndexPath) {
|
|
128
|
+
await serveInjectedIndexHtml(paths.standaloneIndexPath, paths.endpoint, response);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
await streamFile(requestedPath, response);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (extname(pathname)) {
|
|
136
|
+
response.statusCode = 404;
|
|
137
|
+
response.end("Not found");
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
await serveInjectedIndexHtml(paths.standaloneIndexPath, paths.endpoint, response);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function readFlagValue(flag: string): string | null {
|
|
145
|
+
const flagIndex = process.argv.indexOf(flag);
|
|
146
|
+
const value = flagIndex >= 0 ? process.argv[flagIndex + 1] : undefined;
|
|
147
|
+
return value ? value : null;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function isPathInsideRoot(root: string, path: string): boolean {
|
|
151
|
+
const relativePath = relative(root, path);
|
|
152
|
+
return (
|
|
153
|
+
relativePath === "" ||
|
|
154
|
+
(!relativePath.startsWith(`..${sep}`) &&
|
|
155
|
+
relativePath !== ".." &&
|
|
156
|
+
!relativePath.includes(`${sep}..${sep}`))
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
async function safeStat(path: string) {
|
|
161
|
+
try {
|
|
162
|
+
return await stat(path);
|
|
163
|
+
} catch {
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
async function streamFile(
|
|
169
|
+
path: string,
|
|
170
|
+
response: import("node:http").ServerResponse,
|
|
171
|
+
): Promise<void> {
|
|
172
|
+
await access(path);
|
|
173
|
+
response.statusCode = 200;
|
|
174
|
+
response.setHeader("content-type", contentTypeForPath(path));
|
|
175
|
+
|
|
176
|
+
await new Promise<void>((resolvePromise, rejectPromise) => {
|
|
177
|
+
const stream = createReadStream(path);
|
|
178
|
+
stream.on("error", rejectPromise);
|
|
179
|
+
response.on("finish", resolvePromise);
|
|
180
|
+
response.on("close", resolvePromise);
|
|
181
|
+
stream.pipe(response);
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
async function serveInjectedIndexHtml(
|
|
186
|
+
path: string,
|
|
187
|
+
endpoint: string,
|
|
188
|
+
response: import("node:http").ServerResponse,
|
|
189
|
+
): Promise<void> {
|
|
190
|
+
const html = await readFile(path, "utf8");
|
|
191
|
+
response.statusCode = 200;
|
|
192
|
+
response.setHeader("content-type", "text/html; charset=utf-8");
|
|
193
|
+
response.end(injectEndpointIntoHtml(html, endpoint));
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function contentTypeForPath(path: string): string {
|
|
197
|
+
return CONTENT_TYPES[extname(path).toLowerCase()] ?? "application/octet-stream";
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function injectEndpointIntoHtml(html: string, endpoint: string): string {
|
|
201
|
+
const configScript = `<script>window.__EVENTUALLY_UI_ENDPOINT__=${JSON.stringify(endpoint)};</script>`;
|
|
202
|
+
return html.includes("</head>")
|
|
203
|
+
? html.replace("</head>", `${configScript}</head>`)
|
|
204
|
+
: `${configScript}${html}`;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function readPathname(rawUrl: string): string | null {
|
|
208
|
+
try {
|
|
209
|
+
return decodeURIComponent(new URL(rawUrl, "http://localhost").pathname);
|
|
210
|
+
} catch {
|
|
211
|
+
return null;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
void main();
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
|
|
3
|
+
import { cleanup, render, screen, waitFor } from "@testing-library/react";
|
|
4
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
5
|
+
|
|
6
|
+
import { EventuallyUIProvider, useEventuallyUI } from "./context.js";
|
|
7
|
+
|
|
8
|
+
function Probe() {
|
|
9
|
+
const { error, stale } = useEventuallyUI();
|
|
10
|
+
|
|
11
|
+
return (
|
|
12
|
+
<div>
|
|
13
|
+
<span data-testid="stale">{String(stale)}</span>
|
|
14
|
+
<span data-testid="error">{error ?? "none"}</span>
|
|
15
|
+
</div>
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
describe("EventuallyUIProvider", () => {
|
|
20
|
+
afterEach(() => {
|
|
21
|
+
cleanup();
|
|
22
|
+
vi.unstubAllGlobals();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("surfaces refresh failures to consumers", async () => {
|
|
26
|
+
vi.stubGlobal(
|
|
27
|
+
"fetch",
|
|
28
|
+
vi.fn().mockResolvedValue({
|
|
29
|
+
ok: false,
|
|
30
|
+
status: 503,
|
|
31
|
+
}),
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
render(
|
|
35
|
+
<EventuallyUIProvider endpoint="/api/playground" refreshInterval={10_000}>
|
|
36
|
+
<Probe />
|
|
37
|
+
</EventuallyUIProvider>,
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
await waitFor(() => {
|
|
41
|
+
expect(screen.getByTestId("stale").textContent).toBe("true");
|
|
42
|
+
expect(screen.getByTestId("error").textContent).toBe(
|
|
43
|
+
"Eventually UI refresh failed with 503",
|
|
44
|
+
);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
});
|
package/src/context.tsx
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createContext,
|
|
3
|
+
startTransition,
|
|
4
|
+
useContext,
|
|
5
|
+
useEffect,
|
|
6
|
+
useMemo,
|
|
7
|
+
useState,
|
|
8
|
+
type ReactNode,
|
|
9
|
+
} from "react";
|
|
10
|
+
|
|
11
|
+
import type { EventuallyUIAction, EventuallyUISnapshot } from "./types.js";
|
|
12
|
+
|
|
13
|
+
interface EventuallyUIContextValue {
|
|
14
|
+
endpoint: string;
|
|
15
|
+
error: string | null;
|
|
16
|
+
pending: string | null;
|
|
17
|
+
snapshot: EventuallyUISnapshot | null;
|
|
18
|
+
stale: boolean;
|
|
19
|
+
refresh(): Promise<void>;
|
|
20
|
+
perform(action: EventuallyUIAction, label?: string): Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const EventuallyUIContext = createContext<EventuallyUIContextValue | null>(
|
|
24
|
+
null,
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
export function EventuallyUIProvider({
|
|
28
|
+
children,
|
|
29
|
+
endpoint = "http://localhost:3210/api/playground",
|
|
30
|
+
refreshInterval = 1200,
|
|
31
|
+
initialSnapshot = null,
|
|
32
|
+
}: {
|
|
33
|
+
children: ReactNode;
|
|
34
|
+
endpoint?: string;
|
|
35
|
+
refreshInterval?: number;
|
|
36
|
+
initialSnapshot?: EventuallyUISnapshot | null;
|
|
37
|
+
}) {
|
|
38
|
+
const [snapshot, setSnapshot] = useState<EventuallyUISnapshot | null>(
|
|
39
|
+
initialSnapshot,
|
|
40
|
+
);
|
|
41
|
+
const [error, setError] = useState<string | null>(null);
|
|
42
|
+
const [pending, setPending] = useState<string | null>(null);
|
|
43
|
+
|
|
44
|
+
async function refresh() {
|
|
45
|
+
const response = await fetch(endpoint, { cache: "no-store" });
|
|
46
|
+
if (!response.ok) {
|
|
47
|
+
throw new Error(`Eventually UI refresh failed with ${response.status}`);
|
|
48
|
+
}
|
|
49
|
+
const next = (await response.json()) as EventuallyUISnapshot;
|
|
50
|
+
setError(null);
|
|
51
|
+
startTransition(() => {
|
|
52
|
+
setSnapshot(next);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async function perform(action: EventuallyUIAction, label = action.action) {
|
|
57
|
+
setPending(label);
|
|
58
|
+
try {
|
|
59
|
+
const response = await fetch(endpoint, {
|
|
60
|
+
method: "POST",
|
|
61
|
+
headers: {
|
|
62
|
+
"content-type": "application/json",
|
|
63
|
+
},
|
|
64
|
+
body: JSON.stringify(action),
|
|
65
|
+
});
|
|
66
|
+
if (!response.ok) {
|
|
67
|
+
throw new Error(`Eventually UI action failed with ${response.status}`);
|
|
68
|
+
}
|
|
69
|
+
const next = (await response.json()) as EventuallyUISnapshot;
|
|
70
|
+
setError(null);
|
|
71
|
+
startTransition(() => {
|
|
72
|
+
setSnapshot(next);
|
|
73
|
+
});
|
|
74
|
+
} catch (error) {
|
|
75
|
+
setError(
|
|
76
|
+
error instanceof Error ? error.message : "Eventually UI request failed",
|
|
77
|
+
);
|
|
78
|
+
throw error;
|
|
79
|
+
} finally {
|
|
80
|
+
setPending(null);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
void refresh().catch((error) => {
|
|
86
|
+
setError(
|
|
87
|
+
error instanceof Error ? error.message : "Eventually UI refresh failed",
|
|
88
|
+
);
|
|
89
|
+
});
|
|
90
|
+
const timer = window.setInterval(() => {
|
|
91
|
+
void refresh().catch((error) => {
|
|
92
|
+
setError(
|
|
93
|
+
error instanceof Error
|
|
94
|
+
? error.message
|
|
95
|
+
: "Eventually UI refresh failed",
|
|
96
|
+
);
|
|
97
|
+
});
|
|
98
|
+
}, refreshInterval);
|
|
99
|
+
return () => window.clearInterval(timer);
|
|
100
|
+
}, [endpoint, refreshInterval]);
|
|
101
|
+
|
|
102
|
+
const value = useMemo(
|
|
103
|
+
() => ({
|
|
104
|
+
endpoint,
|
|
105
|
+
error,
|
|
106
|
+
pending,
|
|
107
|
+
snapshot,
|
|
108
|
+
stale: error !== null,
|
|
109
|
+
refresh,
|
|
110
|
+
perform,
|
|
111
|
+
}),
|
|
112
|
+
[endpoint, error, pending, snapshot],
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
return (
|
|
116
|
+
<EventuallyUIContext.Provider value={value}>
|
|
117
|
+
{children}
|
|
118
|
+
</EventuallyUIContext.Provider>
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function useEventuallyUI() {
|
|
123
|
+
const context = useContext(EventuallyUIContext);
|
|
124
|
+
if (!context) {
|
|
125
|
+
throw new Error(
|
|
126
|
+
"useEventuallyUI must be used inside EventuallyUIProvider.",
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
return context;
|
|
130
|
+
}
|