@krak-stack/registry 0.11.1 → 0.11.2

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 (34) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/components/agent/react.js +29 -183
  3. package/dist/components/animated-list/react.js +16 -168
  4. package/dist/components/animated-number/react.js +8 -162
  5. package/dist/components/async-action-button/react.js +10 -164
  6. package/dist/components/audit-log-table/react.js +59 -213
  7. package/dist/components/code-block/react.js +10 -164
  8. package/dist/components/copy-button/react.js +10 -164
  9. package/dist/components/copy-value/html.js +4 -4
  10. package/dist/components/copy-value/react.js +20 -172
  11. package/dist/components/danger-confirmation/react.js +13 -167
  12. package/dist/components/data-table/react.js +59 -213
  13. package/dist/components/editable-text/react.js +14 -168
  14. package/dist/components/email-composer/react.js +25 -174
  15. package/dist/components/email-editor/react.js +34 -186
  16. package/dist/components/error-component/react.js +15 -169
  17. package/dist/components/icon-input/react.js +7 -161
  18. package/dist/components/image-crop-editor/react.js +19 -173
  19. package/dist/components/markdown/react.js +10 -164
  20. package/dist/components/presence-transition/react.js +9 -163
  21. package/dist/components/registry-previews/component-example.js +10 -164
  22. package/dist/components/rich-text-editor/react.js +9 -161
  23. package/dist/components/search-menu/react.js +11 -165
  24. package/dist/components/sidebar-layout/react.js +3 -157
  25. package/dist/components/support/react.js +14 -168
  26. package/dist/components/timezone-input/react.js +9 -163
  27. package/dist/components/webhook-delivery-table/react.js +74 -226
  28. package/dist/lib/docs.integrations.server.js +16 -35
  29. package/dist/lib/docs.js +31 -183
  30. package/dist/lib/docs.server.js +16 -35
  31. package/dist/lib/documentation-toolkit.js +19 -38
  32. package/dist/lib/effect-ui-adapter/use-model.js +158 -0
  33. package/dist/services/agent/client/index.js +29 -183
  34. package/package.json +5 -1
@@ -1,5 +1,5 @@
1
1
  // ../../src/components/icon-input/react.tsx
2
- import { Component as Component3, View as View2 } from "effect/ui";
2
+ import { Component as Component3, View } from "effect/ui";
3
3
  import { Icon } from "@iconify/react";
4
4
  import { ExternalLink, Search } from "lucide-react";
5
5
 
@@ -564,164 +564,10 @@ function VirtualizedCombobox(props) {
564
564
 
565
565
  // ../../src/components/icon-input/react.tsx
566
566
  import { useKrakstackLocale as useKrakstackLocale2 } from "@krak-stack/registry/krakstack-provider/react";
567
-
568
- // ../../src/lib/effect-ui-adapter/use-model.ts
569
- import { MessageLog as MessageLog2 } from "effect/ui";
570
- import {
571
- createContext,
572
- useCallback as useCallback2,
573
- useContext,
574
- useEffect as useEffect2,
575
- useLayoutEffect,
576
- useRef as useRef2,
577
- useState,
578
- useSyncExternalStore
579
- } from "react";
580
-
581
- // ../../src/lib/effect-ui-adapter/model-runtime.ts
582
- import { MessageLog, Renderer, View } from "effect/ui";
583
- import { BrowserHost, Html } from "effect/ui/html";
584
- import { Cause, Effect, Fiber } from "effect";
585
- var node = () => ({ children: [] });
586
- var modelHost = (commit) => {
587
- const remove = (child) => {
588
- if (!child.parent)
589
- return;
590
- child.parent.children.splice(child.parent.children.indexOf(child), 1);
591
- delete child.parent;
592
- };
593
- return {
594
- createElement: node,
595
- createText: node,
596
- setText: () => {},
597
- setAttr: () => {},
598
- setProp: () => {},
599
- setEvents: () => {},
600
- insertBefore: (parent, child, before) => {
601
- if (child === before)
602
- return;
603
- remove(child);
604
- const index = before ? parent.children.indexOf(before) : parent.children.length;
605
- parent.children.splice(index, 0, child);
606
- child.parent = parent;
607
- },
608
- remove,
609
- parentOf: (child) => child.parent,
610
- nextOf: (child) => child.parent?.children[child.parent.children.indexOf(child) + 1],
611
- elements: ["html"],
612
- controlled: new Set,
613
- runsMounts: false,
614
- commit
615
- };
616
- };
617
- var mountModel = (component, props, publishSnapshot, messageLog, onEmit) => {
618
- let currentProps = props;
619
- let root;
620
- let active = true;
621
- let failure;
622
- const publish = () => {
623
- if (!active)
624
- return;
625
- if (failure) {
626
- publishSnapshot({ error: failure });
627
- return;
628
- }
629
- const current = root?.model();
630
- if (current !== undefined)
631
- publishSnapshot({ model: current });
632
- };
633
- const fiber = Effect.runFork(Effect.scoped(Effect.gen(function* () {
634
- const mounted = yield* Renderer.mount(component, Effect.succeed(props), node(), {
635
- head: false,
636
- onEmit,
637
- fallback: ({ cause }) => {
638
- failure = new Error("Effect UI root failed", {
639
- cause: Cause.squash(cause)
640
- });
641
- return View.text("");
642
- }
643
- });
644
- if (!active)
645
- return;
646
- root = mounted;
647
- if (props !== currentProps)
648
- mounted.setProps(currentProps);
649
- publish();
650
- return yield* Effect.never;
651
- }).pipe(Effect.provide(Renderer.layer(modelHost(publish))), Effect.provideService(Html.Host, BrowserHost.htmlHost), Effect.provideService(MessageLog.MessageLog, messageLog))));
652
- return {
653
- send: (message) => {
654
- root?.send(message);
655
- publish();
656
- },
657
- setProps: (next) => {
658
- currentProps = next;
659
- root?.setProps(next);
660
- },
661
- dispose: () => {
662
- active = false;
663
- root = undefined;
664
- Effect.runFork(Fiber.interrupt(fiber));
665
- }
666
- };
667
- };
668
-
669
- // ../../src/lib/effect-ui-adapter/use-model.ts
670
- "use client";
671
- var ModelMessageLogContext = createContext(undefined);
672
- var useModel = (component, props, options = {}) => {
673
- const contextLog = useContext(ModelMessageLogContext);
674
- const messageLog = options.messageLog ?? (contextLog === undefined ? MessageLog2.noop : contextLog);
675
- const [store] = useState(() => {
676
- const initial = { model: component.init(props).model };
677
- let snapshot = initial;
678
- const listeners = new Set;
679
- return {
680
- subscribe: (listener) => {
681
- listeners.add(listener);
682
- return () => {
683
- listeners.delete(listener);
684
- };
685
- },
686
- getSnapshot: () => snapshot,
687
- getServerSnapshot: () => initial,
688
- publish: (next) => {
689
- if ("model" in snapshot && "model" in next && Object.is(snapshot.model, next.model))
690
- return;
691
- if ("error" in snapshot && "error" in next && snapshot.error === next.error)
692
- return;
693
- snapshot = next;
694
- listeners.forEach((listener) => listener());
695
- }
696
- };
697
- });
698
- const snapshot = useSyncExternalStore(store.subscribe, store.getSnapshot, store.getServerSnapshot);
699
- const committed = useRef2(props);
700
- const onEmit = useRef2(options.onEmit);
701
- const runtime = useRef2(undefined);
702
- const send = useCallback2((message) => runtime.current?.send(message), []);
703
- useLayoutEffect(() => {
704
- onEmit.current = options.onEmit;
705
- committed.current = props;
706
- runtime.current?.setProps(props);
707
- }, [props, options.onEmit]);
708
- useEffect2(() => {
709
- if (messageLog === null)
710
- return;
711
- const mounted = mountModel(component, committed.current, store.publish, messageLog, (event) => onEmit.current?.(event));
712
- runtime.current = mounted;
713
- return () => {
714
- runtime.current = undefined;
715
- mounted.dispose();
716
- };
717
- }, [component, messageLog, store]);
718
- if ("error" in snapshot)
719
- throw snapshot.error;
720
- return { model: snapshot.model, send };
721
- };
567
+ import { useModel } from "@krak-stack/registry/effect-ui-adapter/react";
722
568
 
723
569
  // ../../src/components/icon-input/index.ts
724
- import { Effect as Effect2, Schema as Schema4, Stream } from "effect";
570
+ import { Effect, Schema as Schema4, Stream } from "effect";
725
571
  import {
726
572
  FetchHttpClient,
727
573
  HttpClient,
@@ -781,7 +627,7 @@ var iconInputLabels = (locale, messages) => ({
781
627
  ...messages?.[locale]
782
628
  });
783
629
  var iconifyCollectionUrl = (collection) => `https://icon-sets.iconify.design/${encodeURIComponent(collection)}/`;
784
- var searchIcons = (collection, query) => Effect2.gen(function* () {
630
+ var searchIcons = (collection, query) => Effect.gen(function* () {
785
631
  if (!query.trim())
786
632
  return [];
787
633
  const client = yield* HttpClient.HttpClient;
@@ -789,7 +635,7 @@ var searchIcons = (collection, query) => Effect2.gen(function* () {
789
635
  const response = yield* client.execute(request);
790
636
  const { icons } = yield* HttpClientResponse.schemaBodyJson(IconifySearchResponse)(response);
791
637
  return icons.filter((icon) => icon.startsWith(`${collection}:`)).map((icon) => icon.slice(collection.length + 1));
792
- }).pipe(Effect2.provideService(HttpClient.TracerPropagationEnabled, false), Effect2.provide(FetchHttpClient.layer));
638
+ }).pipe(Effect.provideService(HttpClient.TracerPropagationEnabled, false), Effect.provide(FetchHttpClient.layer));
793
639
  var emptyResults = [];
794
640
  var IconInputMessage = UiSchema2.TaggedEnum({
795
641
  OpenChanged: { open: Schema4.Boolean },
@@ -858,7 +704,7 @@ var iconInputBehaviours = {
858
704
  model,
859
705
  props
860
706
  }) => !model.open || !model.query.trim() ? [] : [
861
- Subscription.make("iconify-search", [props.collection ?? "lucide", model.query], ([collection, query]) => Stream.fromEffect(searchIcons(collection, query).pipe(Effect2.delay("120 millis"), Effect2.orElseSucceed(() => emptyResults), Effect2.map((icons) => IconInputMessage.Results({ collection, query, icons })))))
707
+ Subscription.make("iconify-search", [props.collection ?? "lucide", model.query], ([collection, query]) => Stream.fromEffect(searchIcons(collection, query).pipe(Effect.delay("120 millis"), Effect.orElseSucceed(() => emptyResults), Effect.map((icons) => IconInputMessage.Results({ collection, query, icons })))))
862
708
  ]
863
709
  };
864
710
 
@@ -866,7 +712,7 @@ var iconInputBehaviours = {
866
712
  import { jsx as jsx5, jsxs as jsxs2, Fragment as Fragment2 } from "react/jsx-runtime";
867
713
  var IconInputModel = Component3.define(iconInputOptions).make({
868
714
  ...iconInputBehaviours,
869
- view: () => View2.text("")
715
+ view: () => View.text("")
870
716
  });
871
717
  function IconInput({
872
718
  collection = "lucide",
@@ -1,10 +1,10 @@
1
1
  // ../../src/components/image-crop-editor/react.tsx
2
- import { useCallback as useCallback2, useEffect as useEffect2, useRef as useRef3, useState as useState3 } from "react";
2
+ import { useCallback, useEffect, useRef as useRef2, useState as useState2 } from "react";
3
3
 
4
4
  // ../../src/components/async-action-button/react.tsx
5
5
  import { Check, LoaderCircle, RotateCcw } from "lucide-react";
6
6
  import { Component as Component2 } from "effect/ui";
7
- import { useLayoutEffect as useLayoutEffect2, useRef as useRef2, useState as useState2 } from "react";
7
+ import { useLayoutEffect, useRef, useState } from "react";
8
8
 
9
9
  // ../../src/components/ui/button.tsx
10
10
  import { Button as ButtonPrimitive } from "@base-ui/react/button";
@@ -56,161 +56,7 @@ function Button({
56
56
 
57
57
  // ../../src/components/async-action-button/react.tsx
58
58
  import { useKrakstackLocale } from "@krak-stack/registry/krakstack-provider/react";
59
-
60
- // ../../src/lib/effect-ui-adapter/use-model.ts
61
- import { MessageLog as MessageLog2 } from "effect/ui";
62
- import {
63
- createContext,
64
- useCallback,
65
- useContext,
66
- useEffect,
67
- useLayoutEffect,
68
- useRef,
69
- useState,
70
- useSyncExternalStore
71
- } from "react";
72
-
73
- // ../../src/lib/effect-ui-adapter/model-runtime.ts
74
- import { MessageLog, Renderer, View } from "effect/ui";
75
- import { BrowserHost, Html } from "effect/ui/html";
76
- import { Cause, Effect, Fiber } from "effect";
77
- var node = () => ({ children: [] });
78
- var modelHost = (commit) => {
79
- const remove = (child) => {
80
- if (!child.parent)
81
- return;
82
- child.parent.children.splice(child.parent.children.indexOf(child), 1);
83
- delete child.parent;
84
- };
85
- return {
86
- createElement: node,
87
- createText: node,
88
- setText: () => {},
89
- setAttr: () => {},
90
- setProp: () => {},
91
- setEvents: () => {},
92
- insertBefore: (parent, child, before) => {
93
- if (child === before)
94
- return;
95
- remove(child);
96
- const index = before ? parent.children.indexOf(before) : parent.children.length;
97
- parent.children.splice(index, 0, child);
98
- child.parent = parent;
99
- },
100
- remove,
101
- parentOf: (child) => child.parent,
102
- nextOf: (child) => child.parent?.children[child.parent.children.indexOf(child) + 1],
103
- elements: ["html"],
104
- controlled: new Set,
105
- runsMounts: false,
106
- commit
107
- };
108
- };
109
- var mountModel = (component, props, publishSnapshot, messageLog, onEmit) => {
110
- let currentProps = props;
111
- let root;
112
- let active = true;
113
- let failure;
114
- const publish = () => {
115
- if (!active)
116
- return;
117
- if (failure) {
118
- publishSnapshot({ error: failure });
119
- return;
120
- }
121
- const current = root?.model();
122
- if (current !== undefined)
123
- publishSnapshot({ model: current });
124
- };
125
- const fiber = Effect.runFork(Effect.scoped(Effect.gen(function* () {
126
- const mounted = yield* Renderer.mount(component, Effect.succeed(props), node(), {
127
- head: false,
128
- onEmit,
129
- fallback: ({ cause }) => {
130
- failure = new Error("Effect UI root failed", {
131
- cause: Cause.squash(cause)
132
- });
133
- return View.text("");
134
- }
135
- });
136
- if (!active)
137
- return;
138
- root = mounted;
139
- if (props !== currentProps)
140
- mounted.setProps(currentProps);
141
- publish();
142
- return yield* Effect.never;
143
- }).pipe(Effect.provide(Renderer.layer(modelHost(publish))), Effect.provideService(Html.Host, BrowserHost.htmlHost), Effect.provideService(MessageLog.MessageLog, messageLog))));
144
- return {
145
- send: (message) => {
146
- root?.send(message);
147
- publish();
148
- },
149
- setProps: (next) => {
150
- currentProps = next;
151
- root?.setProps(next);
152
- },
153
- dispose: () => {
154
- active = false;
155
- root = undefined;
156
- Effect.runFork(Fiber.interrupt(fiber));
157
- }
158
- };
159
- };
160
-
161
- // ../../src/lib/effect-ui-adapter/use-model.ts
162
- "use client";
163
- var ModelMessageLogContext = createContext(undefined);
164
- var useModel = (component, props, options = {}) => {
165
- const contextLog = useContext(ModelMessageLogContext);
166
- const messageLog = options.messageLog ?? (contextLog === undefined ? MessageLog2.noop : contextLog);
167
- const [store] = useState(() => {
168
- const initial = { model: component.init(props).model };
169
- let snapshot = initial;
170
- const listeners = new Set;
171
- return {
172
- subscribe: (listener) => {
173
- listeners.add(listener);
174
- return () => {
175
- listeners.delete(listener);
176
- };
177
- },
178
- getSnapshot: () => snapshot,
179
- getServerSnapshot: () => initial,
180
- publish: (next) => {
181
- if ("model" in snapshot && "model" in next && Object.is(snapshot.model, next.model))
182
- return;
183
- if ("error" in snapshot && "error" in next && snapshot.error === next.error)
184
- return;
185
- snapshot = next;
186
- listeners.forEach((listener) => listener());
187
- }
188
- };
189
- });
190
- const snapshot = useSyncExternalStore(store.subscribe, store.getSnapshot, store.getServerSnapshot);
191
- const committed = useRef(props);
192
- const onEmit = useRef(options.onEmit);
193
- const runtime = useRef(undefined);
194
- const send = useCallback((message) => runtime.current?.send(message), []);
195
- useLayoutEffect(() => {
196
- onEmit.current = options.onEmit;
197
- committed.current = props;
198
- runtime.current?.setProps(props);
199
- }, [props, options.onEmit]);
200
- useEffect(() => {
201
- if (messageLog === null)
202
- return;
203
- const mounted = mountModel(component, committed.current, store.publish, messageLog, (event) => onEmit.current?.(event));
204
- runtime.current = mounted;
205
- return () => {
206
- runtime.current = undefined;
207
- mounted.dispose();
208
- };
209
- }, [component, messageLog, store]);
210
- if ("error" in snapshot)
211
- throw snapshot.error;
212
- return { model: snapshot.model, send };
213
- };
59
+ import { useModel } from "@krak-stack/registry/effect-ui-adapter/react";
214
60
 
215
61
  // ../../src/components/async-action-button/classes.ts
216
62
  var asyncActionButtonClasses = {
@@ -224,8 +70,8 @@ var resolveAsyncActionButtonClasses = (overrides) => ({
224
70
  });
225
71
 
226
72
  // ../../src/components/async-action-button/index.ts
227
- import { Effect as Effect2, Schema as Schema2 } from "effect";
228
- import { Command, Component, UiSchema, View as View2 } from "effect/ui";
73
+ import { Effect, Schema as Schema2 } from "effect";
74
+ import { Command, Component, UiSchema, View } from "effect/ui";
229
75
 
230
76
  // ../../src/components/async-action-button/schema.ts
231
77
  import { Schema, Struct } from "effect";
@@ -275,11 +121,11 @@ var AsyncActionButtonMessage = UiSchema.TaggedEnum({
275
121
  }).annotate({ identifier: "AsyncActionButtonMessage" });
276
122
 
277
123
  class RunAsyncAction extends Command.Service()("async-action-button/RunAsyncAction", { args: {}, success: AsyncActionButtonMessage }) {
278
- static layerFromEffect = (run) => RunAsyncAction.toLayer(() => Effect2.suspend(run).pipe(Effect2.match({
124
+ static layerFromEffect = (run) => RunAsyncAction.toLayer(() => Effect.suspend(run).pipe(Effect.match({
279
125
  onSuccess: () => AsyncActionButtonMessage.Finished({ success: true }),
280
126
  onFailure: () => AsyncActionButtonMessage.Finished({ success: false })
281
127
  })));
282
- static layerFromAction = (run) => RunAsyncAction.layerFromEffect(() => Effect2.tryPromise(() => run()));
128
+ static layerFromAction = (run) => RunAsyncAction.layerFromEffect(() => Effect.tryPromise(() => run()));
283
129
  }
284
130
  var asyncActionButtonOptions = {
285
131
  name: "AsyncActionButton",
@@ -301,7 +147,7 @@ var asyncActionButtonBehaviours = {
301
147
  };
302
148
  var AsyncActionButtonModel = Definition.make({
303
149
  ...asyncActionButtonBehaviours,
304
- view: () => View2.text("")
150
+ view: () => View.text("")
305
151
  });
306
152
  var getAsyncActionButtonFeedback = (status, copy) => ({
307
153
  label: status === "idle" ? undefined : status === "error" ? copy.retry : copy[status],
@@ -324,11 +170,11 @@ var AsyncActionButton = ({
324
170
  }) => {
325
171
  const asyncActionButtonClasses = resolveAsyncActionButtonClasses(classOverrides);
326
172
  const copy = getAsyncActionButtonMessages(useKrakstackLocale(override), messages);
327
- const callbacks = useRef2({ onAction, onPendingChange });
328
- useLayoutEffect2(() => {
173
+ const callbacks = useRef({ onAction, onPendingChange });
174
+ useLayoutEffect(() => {
329
175
  callbacks.current = { onAction, onPendingChange };
330
176
  }, [onAction, onPendingChange]);
331
- const [component] = useState2(() => AsyncActionButtonModel.pipe(Component2.provide(RunAsyncAction.layerFromAction(async () => {
177
+ const [component] = useState(() => AsyncActionButtonModel.pipe(Component2.provide(RunAsyncAction.layerFromAction(async () => {
332
178
  const { onAction, onPendingChange } = callbacks.current;
333
179
  onPendingChange?.(true);
334
180
  try {
@@ -633,11 +479,11 @@ var ImageCropSession = ({
633
479
  const imageCropEditorClasses = resolveImageCropEditorClasses(classOverrides);
634
480
  const locale = useKrakstackLocale2(override);
635
481
  const copy = getImageCropMessages(locale, messages);
636
- const image = useRef3(null);
637
- const [size, setSize] = useState3();
638
- const [failed, setFailed] = useState3(false);
639
- const [pending, setPending] = useState3(false);
640
- const attachImage = useCallback2((element) => {
482
+ const image = useRef2(null);
483
+ const [size, setSize] = useState2();
484
+ const [failed, setFailed] = useState2(false);
485
+ const [pending, setPending] = useState2(false);
486
+ const attachImage = useCallback((element) => {
641
487
  image.current = element;
642
488
  if (!element?.complete)
643
489
  return;
@@ -646,14 +492,14 @@ var ImageCropSession = ({
646
492
  } else
647
493
  setFailed(true);
648
494
  }, []);
649
- const mounted = useRef3(false);
650
- useEffect2(() => {
495
+ const mounted = useRef2(false);
496
+ useEffect(() => {
651
497
  mounted.current = true;
652
498
  return () => {
653
499
  mounted.current = false;
654
500
  };
655
501
  }, []);
656
- const drag = useRef3(null);
502
+ const drag = useRef2(null);
657
503
  const crop = size ? getImageCropGeometry(size.width, size.height, value, aspectRatio) : undefined;
658
504
  const transform = size ? imageCropTransform(size.width, size.height, value.rotation) : undefined;
659
505
  const locked = disabled || pending;
@@ -50,167 +50,13 @@ function Button({
50
50
  import { Check, Copy, TriangleAlert } from "lucide-react";
51
51
  import { Redacted as Redacted2 } from "effect";
52
52
  import { Component as Component2 } from "effect/ui";
53
- import { useLayoutEffect as useLayoutEffect2, useRef as useRef2, useState as useState2 } from "react";
53
+ import { useLayoutEffect, useRef, useState } from "react";
54
54
  import { useKrakstackLocale } from "@krak-stack/registry/krakstack-provider/react";
55
-
56
- // ../../src/lib/effect-ui-adapter/use-model.ts
57
- import { MessageLog as MessageLog2 } from "effect/ui";
58
- import {
59
- createContext,
60
- useCallback,
61
- useContext,
62
- useEffect,
63
- useLayoutEffect,
64
- useRef,
65
- useState,
66
- useSyncExternalStore
67
- } from "react";
68
-
69
- // ../../src/lib/effect-ui-adapter/model-runtime.ts
70
- import { MessageLog, Renderer, View } from "effect/ui";
71
- import { BrowserHost, Html } from "effect/ui/html";
72
- import { Cause, Effect, Fiber } from "effect";
73
- var node = () => ({ children: [] });
74
- var modelHost = (commit) => {
75
- const remove = (child) => {
76
- if (!child.parent)
77
- return;
78
- child.parent.children.splice(child.parent.children.indexOf(child), 1);
79
- delete child.parent;
80
- };
81
- return {
82
- createElement: node,
83
- createText: node,
84
- setText: () => {},
85
- setAttr: () => {},
86
- setProp: () => {},
87
- setEvents: () => {},
88
- insertBefore: (parent, child, before) => {
89
- if (child === before)
90
- return;
91
- remove(child);
92
- const index = before ? parent.children.indexOf(before) : parent.children.length;
93
- parent.children.splice(index, 0, child);
94
- child.parent = parent;
95
- },
96
- remove,
97
- parentOf: (child) => child.parent,
98
- nextOf: (child) => child.parent?.children[child.parent.children.indexOf(child) + 1],
99
- elements: ["html"],
100
- controlled: new Set,
101
- runsMounts: false,
102
- commit
103
- };
104
- };
105
- var mountModel = (component, props, publishSnapshot, messageLog, onEmit) => {
106
- let currentProps = props;
107
- let root;
108
- let active = true;
109
- let failure;
110
- const publish = () => {
111
- if (!active)
112
- return;
113
- if (failure) {
114
- publishSnapshot({ error: failure });
115
- return;
116
- }
117
- const current = root?.model();
118
- if (current !== undefined)
119
- publishSnapshot({ model: current });
120
- };
121
- const fiber = Effect.runFork(Effect.scoped(Effect.gen(function* () {
122
- const mounted = yield* Renderer.mount(component, Effect.succeed(props), node(), {
123
- head: false,
124
- onEmit,
125
- fallback: ({ cause }) => {
126
- failure = new Error("Effect UI root failed", {
127
- cause: Cause.squash(cause)
128
- });
129
- return View.text("");
130
- }
131
- });
132
- if (!active)
133
- return;
134
- root = mounted;
135
- if (props !== currentProps)
136
- mounted.setProps(currentProps);
137
- publish();
138
- return yield* Effect.never;
139
- }).pipe(Effect.provide(Renderer.layer(modelHost(publish))), Effect.provideService(Html.Host, BrowserHost.htmlHost), Effect.provideService(MessageLog.MessageLog, messageLog))));
140
- return {
141
- send: (message) => {
142
- root?.send(message);
143
- publish();
144
- },
145
- setProps: (next) => {
146
- currentProps = next;
147
- root?.setProps(next);
148
- },
149
- dispose: () => {
150
- active = false;
151
- root = undefined;
152
- Effect.runFork(Fiber.interrupt(fiber));
153
- }
154
- };
155
- };
156
-
157
- // ../../src/lib/effect-ui-adapter/use-model.ts
158
- "use client";
159
- var ModelMessageLogContext = createContext(undefined);
160
- var useModel = (component, props, options = {}) => {
161
- const contextLog = useContext(ModelMessageLogContext);
162
- const messageLog = options.messageLog ?? (contextLog === undefined ? MessageLog2.noop : contextLog);
163
- const [store] = useState(() => {
164
- const initial = { model: component.init(props).model };
165
- let snapshot = initial;
166
- const listeners = new Set;
167
- return {
168
- subscribe: (listener) => {
169
- listeners.add(listener);
170
- return () => {
171
- listeners.delete(listener);
172
- };
173
- },
174
- getSnapshot: () => snapshot,
175
- getServerSnapshot: () => initial,
176
- publish: (next) => {
177
- if ("model" in snapshot && "model" in next && Object.is(snapshot.model, next.model))
178
- return;
179
- if ("error" in snapshot && "error" in next && snapshot.error === next.error)
180
- return;
181
- snapshot = next;
182
- listeners.forEach((listener) => listener());
183
- }
184
- };
185
- });
186
- const snapshot = useSyncExternalStore(store.subscribe, store.getSnapshot, store.getServerSnapshot);
187
- const committed = useRef(props);
188
- const onEmit = useRef(options.onEmit);
189
- const runtime = useRef(undefined);
190
- const send = useCallback((message) => runtime.current?.send(message), []);
191
- useLayoutEffect(() => {
192
- onEmit.current = options.onEmit;
193
- committed.current = props;
194
- runtime.current?.setProps(props);
195
- }, [props, options.onEmit]);
196
- useEffect(() => {
197
- if (messageLog === null)
198
- return;
199
- const mounted = mountModel(component, committed.current, store.publish, messageLog, (event) => onEmit.current?.(event));
200
- runtime.current = mounted;
201
- return () => {
202
- runtime.current = undefined;
203
- mounted.dispose();
204
- };
205
- }, [component, messageLog, store]);
206
- if ("error" in snapshot)
207
- throw snapshot.error;
208
- return { model: snapshot.model, send };
209
- };
55
+ import { useModel } from "@krak-stack/registry/effect-ui-adapter/react";
210
56
 
211
57
  // ../../src/components/copy-button/index.ts
212
- import { Effect as Effect2, Redacted, Schema as Schema2 } from "effect";
213
- import { Command, Component, UiSchema, View as View2 } from "effect/ui";
58
+ import { Effect, Redacted, Schema as Schema2 } from "effect";
59
+ import { Command, Component, UiSchema, View } from "effect/ui";
214
60
 
215
61
  // ../../src/components/copy-button/schema.ts
216
62
  import { Schema } from "effect";
@@ -265,13 +111,13 @@ class WriteClipboard extends Command.Service()("copy-button/WriteClipboard", {
265
111
  },
266
112
  success: CopyButtonMessage
267
113
  }) {
268
- static layerFromWrite = (write) => WriteClipboard.toLayer(({ value }) => Effect2.tryPromise(() => write(Redacted.value(value))).pipe(Effect2.match({
114
+ static layerFromWrite = (write) => WriteClipboard.toLayer(({ value }) => Effect.tryPromise(() => write(Redacted.value(value))).pipe(Effect.match({
269
115
  onSuccess: () => CopyButtonMessage.Finished({ success: true }),
270
116
  onFailure: () => CopyButtonMessage.Finished({ success: false })
271
117
  })));
272
118
  static browser = WriteClipboard.layerFromWrite((value) => navigator.clipboard.writeText(value));
273
119
  }
274
- var ResetClipboardFeedback = Command.make("copy-button/ResetFeedback", { args: { delay: Schema2.Number }, mode: "switch" }, ({ delay }) => Effect2.sleep(Math.max(0, delay)).pipe(Effect2.as(CopyButtonMessage.Reset())));
120
+ var ResetClipboardFeedback = Command.make("copy-button/ResetFeedback", { args: { delay: Schema2.Number }, mode: "switch" }, ({ delay }) => Effect.sleep(Math.max(0, delay)).pipe(Effect.as(CopyButtonMessage.Reset())));
275
121
  var copyButtonOptions = {
276
122
  name: "CopyButton",
277
123
  props: CopyButtonModelProps,
@@ -293,7 +139,7 @@ var copyButtonBehaviours = {
293
139
  };
294
140
  var CopyButtonModel = Definition.make({
295
141
  ...copyButtonBehaviours,
296
- view: () => View2.text("")
142
+ view: () => View.text("")
297
143
  });
298
144
  var copyButtonStatus = (status, copy, description) => {
299
145
  if (status === "idle")
@@ -321,19 +167,19 @@ function CopyButton({
321
167
  }) {
322
168
  const locale = useKrakstackLocale(localeOverride);
323
169
  const labels = copyButtonMessages(locale, messages);
324
- const callbacks = useRef2({
170
+ const callbacks = useRef({
325
171
  onCopied,
326
172
  onCopyError,
327
173
  failureLabel: labels.copyFailed
328
174
  });
329
- useLayoutEffect2(() => {
175
+ useLayoutEffect(() => {
330
176
  callbacks.current = {
331
177
  onCopied,
332
178
  onCopyError,
333
179
  failureLabel: labels.copyFailed
334
180
  };
335
181
  }, [onCopied, onCopyError, labels.copyFailed]);
336
- const [component] = useState2(() => CopyButtonModel.pipe(Component2.provide(WriteClipboard.layerFromWrite(async (text) => {
182
+ const [component] = useState(() => CopyButtonModel.pipe(Component2.provide(WriteClipboard.layerFromWrite(async (text) => {
337
183
  const { onCopied, onCopyError, failureLabel } = callbacks.current;
338
184
  try {
339
185
  await navigator.clipboard.writeText(text);