@krak-stack/registry 0.11.1 → 0.11.3
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/CHANGELOG.md +14 -0
- package/README.md +22 -0
- package/dist/components/agent/react.js +29 -183
- package/dist/components/animated-list/html.js +1 -105
- package/dist/components/animated-list/react.js +16 -168
- package/dist/components/animated-number/react.js +8 -162
- package/dist/components/app-switcher/html.js +1 -103
- package/dist/components/async-action-button/html.js +1 -101
- package/dist/components/async-action-button/react.js +10 -164
- package/dist/components/audit-log-table/react.js +59 -213
- package/dist/components/bulk-list-input/html.js +2 -102
- package/dist/components/choice-cards/html.js +1 -101
- package/dist/components/code-block/html.js +1 -101
- package/dist/components/code-block/react.js +10 -164
- package/dist/components/copy-button/html.d.ts +2 -2
- package/dist/components/copy-button/html.js +1 -101
- package/dist/components/copy-button/react.js +10 -164
- package/dist/components/copy-value/html.js +6 -105
- package/dist/components/copy-value/react.js +20 -172
- package/dist/components/danger-confirmation/react.js +13 -167
- package/dist/components/data-table/html.d.ts +51 -51
- package/dist/components/data-table/html.js +28 -101
- package/dist/components/data-table/react.js +59 -213
- package/dist/components/date-input/html.js +2 -105
- package/dist/components/editable-text/html.d.ts +2 -2
- package/dist/components/editable-text/html.js +4 -102
- package/dist/components/editable-text/react.js +14 -168
- package/dist/components/editing-locale-switcher/html.js +2 -102
- package/dist/components/email-composer/react.js +25 -174
- package/dist/components/email-editor/html.js +8 -107
- package/dist/components/email-editor/react.js +34 -186
- package/dist/components/error-component/html.d.ts +4 -4
- package/dist/components/error-component/html.js +10 -107
- package/dist/components/error-component/react.js +15 -169
- package/dist/components/file-input/html.js +6 -106
- package/dist/components/icon-input/html.js +3 -103
- package/dist/components/icon-input/react.js +7 -161
- package/dist/components/image-crop-editor/html.js +1 -101
- package/dist/components/image-crop-editor/react.js +19 -173
- package/dist/components/loading/html.js +1 -101
- package/dist/components/locale-switcher/html.js +1 -103
- package/dist/components/map-menu/html.d.ts +8 -8
- package/dist/components/map-menu/html.js +7 -106
- package/dist/components/markdown/html.js +1 -101
- package/dist/components/markdown/react.js +10 -164
- package/dist/components/notification-menu/html.js +7 -114
- package/dist/components/pagination/html.js +5 -100
- package/dist/components/presence-transition/react.js +9 -163
- package/dist/components/registry-previews/component-example.js +10 -164
- package/dist/components/rich-text-editor/html.js +14 -108
- package/dist/components/rich-text-editor/react.js +9 -161
- package/dist/components/search-menu/html.js +1 -103
- package/dist/components/search-menu/react.js +11 -165
- package/dist/components/sidebar-layout/html.js +2 -102
- package/dist/components/sidebar-layout/react.js +3 -157
- package/dist/components/stepper/html.js +4 -102
- package/dist/components/support/html.js +1 -101
- package/dist/components/support/react.js +14 -168
- package/dist/components/theme-switcher/html.js +4 -105
- package/dist/components/time-input/html.d.ts +2 -2
- package/dist/components/time-input/html.js +1 -103
- package/dist/components/timezone-input/react.js +9 -163
- package/dist/components/toast/html.js +11 -104
- package/dist/components/upload-attachment/html.d.ts +4 -4
- package/dist/components/upload-attachment/html.js +7 -102
- package/dist/components/webhook-delivery-table/html.js +28 -101
- package/dist/components/webhook-delivery-table/react.js +74 -226
- package/dist/lib/docs.integrations.server.js +16 -35
- package/dist/lib/docs.js +31 -183
- package/dist/lib/docs.server.js +16 -35
- package/dist/lib/documentation-toolkit.js +19 -38
- package/dist/lib/effect-ui-adapter/use-model.js +158 -0
- package/dist/lib/lucide-effect.d.ts +2432 -0
- package/dist/lib/lucide-effect.js +7428 -0
- package/dist/services/agent/client/index.js +29 -183
- package/package.json +10 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// ../../src/components/icon-input/react.tsx
|
|
2
|
-
import { Component as Component3, View
|
|
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
|
|
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) =>
|
|
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(
|
|
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(
|
|
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: () =>
|
|
715
|
+
view: () => View.text("")
|
|
870
716
|
});
|
|
871
717
|
function IconInput({
|
|
872
718
|
collection = "lucide",
|
|
@@ -38,107 +38,7 @@ var Button = (h, options = {}) => KitButton(h, {
|
|
|
38
38
|
|
|
39
39
|
// ../../src/components/image-crop-editor/html.ts
|
|
40
40
|
import { krakstackLocaleRead } from "@krak-stack/registry/krakstack-provider/html";
|
|
41
|
-
|
|
42
|
-
// ../../src/lib/lucide-effect.ts
|
|
43
|
-
import {
|
|
44
|
-
ArrowDown as arrowDown,
|
|
45
|
-
ArrowUp as arrowUp,
|
|
46
|
-
ListFilter as listFilter,
|
|
47
|
-
Check as check,
|
|
48
|
-
ChevronLeft as chevronLeft,
|
|
49
|
-
ChevronDown as chevronDown,
|
|
50
|
-
ChevronRight as chevronRight,
|
|
51
|
-
ChevronsLeft as chevronsLeft,
|
|
52
|
-
ChevronsRight as chevronsRight,
|
|
53
|
-
ChevronsUpDown as chevronsUpDown,
|
|
54
|
-
Copy as copy,
|
|
55
|
-
Download as download,
|
|
56
|
-
Eye as eye,
|
|
57
|
-
EyeOff as eyeOff,
|
|
58
|
-
Ellipsis as ellipsis,
|
|
59
|
-
FileJson as fileJson,
|
|
60
|
-
FileText as fileText,
|
|
61
|
-
GripVertical as gripVertical,
|
|
62
|
-
Image as image,
|
|
63
|
-
LayoutGrid as layoutGrid,
|
|
64
|
-
LoaderCircle as loaderCircle,
|
|
65
|
-
Mail as mail,
|
|
66
|
-
Paperclip as paperclip,
|
|
67
|
-
RefreshCw as refreshCw,
|
|
68
|
-
RotateCcw as rotateCcw,
|
|
69
|
-
Rows3 as rows3,
|
|
70
|
-
Search as search,
|
|
71
|
-
Settings2 as settings2,
|
|
72
|
-
TriangleAlert as triangleAlert,
|
|
73
|
-
X as x
|
|
74
|
-
} from "lucide";
|
|
75
|
-
var createLucideIcon = (icon) => (h, {
|
|
76
|
-
size = 24,
|
|
77
|
-
color = "currentColor",
|
|
78
|
-
strokeWidth = 2,
|
|
79
|
-
className
|
|
80
|
-
} = {}) => h.svg.attrs({
|
|
81
|
-
class: className,
|
|
82
|
-
width: String(size),
|
|
83
|
-
height: String(size),
|
|
84
|
-
viewBox: "0 0 24 24",
|
|
85
|
-
fill: "none",
|
|
86
|
-
stroke: color,
|
|
87
|
-
"stroke-width": String(strokeWidth),
|
|
88
|
-
"stroke-linecap": "round",
|
|
89
|
-
"stroke-linejoin": "round",
|
|
90
|
-
"aria-hidden": "true"
|
|
91
|
-
}).children(...icon.map(([tag, attributes]) => {
|
|
92
|
-
const attrs = Object.fromEntries(Object.entries(attributes).flatMap(([name, value]) => value === undefined ? [] : [[name, String(value)]]));
|
|
93
|
-
switch (tag) {
|
|
94
|
-
case "path":
|
|
95
|
-
return h.path.attrs(attrs);
|
|
96
|
-
case "circle":
|
|
97
|
-
return h.circle.attrs(attrs);
|
|
98
|
-
case "ellipse":
|
|
99
|
-
return h.ellipse.attrs(attrs);
|
|
100
|
-
case "line":
|
|
101
|
-
return h.line.attrs(attrs);
|
|
102
|
-
case "polyline":
|
|
103
|
-
return h.polyline.attrs(attrs);
|
|
104
|
-
case "polygon":
|
|
105
|
-
return h.polygon.attrs(attrs);
|
|
106
|
-
case "rect":
|
|
107
|
-
return h.rect.attrs(attrs);
|
|
108
|
-
default:
|
|
109
|
-
throw new Error(`Unsupported Lucide SVG element: ${tag}`);
|
|
110
|
-
}
|
|
111
|
-
}));
|
|
112
|
-
var Check = createLucideIcon(check);
|
|
113
|
-
var ArrowDown = createLucideIcon(arrowDown);
|
|
114
|
-
var ArrowUp = createLucideIcon(arrowUp);
|
|
115
|
-
var ListFilter = createLucideIcon(listFilter);
|
|
116
|
-
var ChevronLeft = createLucideIcon(chevronLeft);
|
|
117
|
-
var ChevronDown = createLucideIcon(chevronDown);
|
|
118
|
-
var ChevronRight = createLucideIcon(chevronRight);
|
|
119
|
-
var ChevronsLeft = createLucideIcon(chevronsLeft);
|
|
120
|
-
var ChevronsRight = createLucideIcon(chevronsRight);
|
|
121
|
-
var ChevronsUpDown = createLucideIcon(chevronsUpDown);
|
|
122
|
-
var Copy = createLucideIcon(copy);
|
|
123
|
-
var Download = createLucideIcon(download);
|
|
124
|
-
var Eye = createLucideIcon(eye);
|
|
125
|
-
var EyeOff = createLucideIcon(eyeOff);
|
|
126
|
-
var Ellipsis = createLucideIcon(ellipsis);
|
|
127
|
-
var FileJson = createLucideIcon(fileJson);
|
|
128
|
-
var FileText = createLucideIcon(fileText);
|
|
129
|
-
var GripVertical = createLucideIcon(gripVertical);
|
|
130
|
-
var Image = createLucideIcon(image);
|
|
131
|
-
var LayoutGrid = createLucideIcon(layoutGrid);
|
|
132
|
-
var LoaderCircle = createLucideIcon(loaderCircle);
|
|
133
|
-
var Mail = createLucideIcon(mail);
|
|
134
|
-
var Paperclip = createLucideIcon(paperclip);
|
|
135
|
-
var RefreshCw = createLucideIcon(refreshCw);
|
|
136
|
-
var RotateCcw = createLucideIcon(rotateCcw);
|
|
137
|
-
var Rows3 = createLucideIcon(rows3);
|
|
138
|
-
var Search = createLucideIcon(search);
|
|
139
|
-
var Settings2 = createLucideIcon(settings2);
|
|
140
|
-
var TriangleAlert = createLucideIcon(triangleAlert);
|
|
141
|
-
var X = createLucideIcon(x);
|
|
41
|
+
import { Check, LoaderCircle, RotateCcw } from "@krak-stack/registry/lucide-effect";
|
|
142
42
|
|
|
143
43
|
// ../../src/components/async-action-button/index.ts
|
|
144
44
|
import { Effect, Schema as Schema2 } from "effect";
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// ../../src/components/image-crop-editor/react.tsx
|
|
2
|
-
import { useCallback
|
|
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
|
|
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
|
|
228
|
-
import { Command, Component, UiSchema, View
|
|
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(() =>
|
|
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(() =>
|
|
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: () =>
|
|
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 =
|
|
328
|
-
|
|
173
|
+
const callbacks = useRef({ onAction, onPendingChange });
|
|
174
|
+
useLayoutEffect(() => {
|
|
329
175
|
callbacks.current = { onAction, onPendingChange };
|
|
330
176
|
}, [onAction, onPendingChange]);
|
|
331
|
-
const [component] =
|
|
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 =
|
|
637
|
-
const [size, setSize] =
|
|
638
|
-
const [failed, setFailed] =
|
|
639
|
-
const [pending, setPending] =
|
|
640
|
-
const attachImage =
|
|
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 =
|
|
650
|
-
|
|
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 =
|
|
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;
|
|
@@ -2,107 +2,7 @@
|
|
|
2
2
|
import { Schema as Schema2 } from "effect";
|
|
3
3
|
import { Html } from "effect/ui/html";
|
|
4
4
|
import { krakstackLocaleRead } from "@krak-stack/registry/krakstack-provider/html";
|
|
5
|
-
|
|
6
|
-
// ../../src/lib/lucide-effect.ts
|
|
7
|
-
import {
|
|
8
|
-
ArrowDown as arrowDown,
|
|
9
|
-
ArrowUp as arrowUp,
|
|
10
|
-
ListFilter as listFilter,
|
|
11
|
-
Check as check,
|
|
12
|
-
ChevronLeft as chevronLeft,
|
|
13
|
-
ChevronDown as chevronDown,
|
|
14
|
-
ChevronRight as chevronRight,
|
|
15
|
-
ChevronsLeft as chevronsLeft,
|
|
16
|
-
ChevronsRight as chevronsRight,
|
|
17
|
-
ChevronsUpDown as chevronsUpDown,
|
|
18
|
-
Copy as copy,
|
|
19
|
-
Download as download,
|
|
20
|
-
Eye as eye,
|
|
21
|
-
EyeOff as eyeOff,
|
|
22
|
-
Ellipsis as ellipsis,
|
|
23
|
-
FileJson as fileJson,
|
|
24
|
-
FileText as fileText,
|
|
25
|
-
GripVertical as gripVertical,
|
|
26
|
-
Image as image,
|
|
27
|
-
LayoutGrid as layoutGrid,
|
|
28
|
-
LoaderCircle as loaderCircle,
|
|
29
|
-
Mail as mail,
|
|
30
|
-
Paperclip as paperclip,
|
|
31
|
-
RefreshCw as refreshCw,
|
|
32
|
-
RotateCcw as rotateCcw,
|
|
33
|
-
Rows3 as rows3,
|
|
34
|
-
Search as search,
|
|
35
|
-
Settings2 as settings2,
|
|
36
|
-
TriangleAlert as triangleAlert,
|
|
37
|
-
X as x
|
|
38
|
-
} from "lucide";
|
|
39
|
-
var createLucideIcon = (icon) => (h, {
|
|
40
|
-
size = 24,
|
|
41
|
-
color = "currentColor",
|
|
42
|
-
strokeWidth = 2,
|
|
43
|
-
className
|
|
44
|
-
} = {}) => h.svg.attrs({
|
|
45
|
-
class: className,
|
|
46
|
-
width: String(size),
|
|
47
|
-
height: String(size),
|
|
48
|
-
viewBox: "0 0 24 24",
|
|
49
|
-
fill: "none",
|
|
50
|
-
stroke: color,
|
|
51
|
-
"stroke-width": String(strokeWidth),
|
|
52
|
-
"stroke-linecap": "round",
|
|
53
|
-
"stroke-linejoin": "round",
|
|
54
|
-
"aria-hidden": "true"
|
|
55
|
-
}).children(...icon.map(([tag, attributes]) => {
|
|
56
|
-
const attrs = Object.fromEntries(Object.entries(attributes).flatMap(([name, value]) => value === undefined ? [] : [[name, String(value)]]));
|
|
57
|
-
switch (tag) {
|
|
58
|
-
case "path":
|
|
59
|
-
return h.path.attrs(attrs);
|
|
60
|
-
case "circle":
|
|
61
|
-
return h.circle.attrs(attrs);
|
|
62
|
-
case "ellipse":
|
|
63
|
-
return h.ellipse.attrs(attrs);
|
|
64
|
-
case "line":
|
|
65
|
-
return h.line.attrs(attrs);
|
|
66
|
-
case "polyline":
|
|
67
|
-
return h.polyline.attrs(attrs);
|
|
68
|
-
case "polygon":
|
|
69
|
-
return h.polygon.attrs(attrs);
|
|
70
|
-
case "rect":
|
|
71
|
-
return h.rect.attrs(attrs);
|
|
72
|
-
default:
|
|
73
|
-
throw new Error(`Unsupported Lucide SVG element: ${tag}`);
|
|
74
|
-
}
|
|
75
|
-
}));
|
|
76
|
-
var Check = createLucideIcon(check);
|
|
77
|
-
var ArrowDown = createLucideIcon(arrowDown);
|
|
78
|
-
var ArrowUp = createLucideIcon(arrowUp);
|
|
79
|
-
var ListFilter = createLucideIcon(listFilter);
|
|
80
|
-
var ChevronLeft = createLucideIcon(chevronLeft);
|
|
81
|
-
var ChevronDown = createLucideIcon(chevronDown);
|
|
82
|
-
var ChevronRight = createLucideIcon(chevronRight);
|
|
83
|
-
var ChevronsLeft = createLucideIcon(chevronsLeft);
|
|
84
|
-
var ChevronsRight = createLucideIcon(chevronsRight);
|
|
85
|
-
var ChevronsUpDown = createLucideIcon(chevronsUpDown);
|
|
86
|
-
var Copy = createLucideIcon(copy);
|
|
87
|
-
var Download = createLucideIcon(download);
|
|
88
|
-
var Eye = createLucideIcon(eye);
|
|
89
|
-
var EyeOff = createLucideIcon(eyeOff);
|
|
90
|
-
var Ellipsis = createLucideIcon(ellipsis);
|
|
91
|
-
var FileJson = createLucideIcon(fileJson);
|
|
92
|
-
var FileText = createLucideIcon(fileText);
|
|
93
|
-
var GripVertical = createLucideIcon(gripVertical);
|
|
94
|
-
var Image = createLucideIcon(image);
|
|
95
|
-
var LayoutGrid = createLucideIcon(layoutGrid);
|
|
96
|
-
var LoaderCircle = createLucideIcon(loaderCircle);
|
|
97
|
-
var Mail = createLucideIcon(mail);
|
|
98
|
-
var Paperclip = createLucideIcon(paperclip);
|
|
99
|
-
var RefreshCw = createLucideIcon(refreshCw);
|
|
100
|
-
var RotateCcw = createLucideIcon(rotateCcw);
|
|
101
|
-
var Rows3 = createLucideIcon(rows3);
|
|
102
|
-
var Search = createLucideIcon(search);
|
|
103
|
-
var Settings2 = createLucideIcon(settings2);
|
|
104
|
-
var TriangleAlert = createLucideIcon(triangleAlert);
|
|
105
|
-
var X = createLucideIcon(x);
|
|
5
|
+
import { LoaderCircle } from "@krak-stack/registry/lucide-effect";
|
|
106
6
|
|
|
107
7
|
// ../../src/lib/utils.ts
|
|
108
8
|
import { cn } from "cn";
|