@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.
- package/CHANGELOG.md +6 -0
- package/dist/components/agent/react.js +29 -183
- package/dist/components/animated-list/react.js +16 -168
- package/dist/components/animated-number/react.js +8 -162
- package/dist/components/async-action-button/react.js +10 -164
- package/dist/components/audit-log-table/react.js +59 -213
- package/dist/components/code-block/react.js +10 -164
- package/dist/components/copy-button/react.js +10 -164
- package/dist/components/copy-value/html.js +4 -4
- package/dist/components/copy-value/react.js +20 -172
- package/dist/components/danger-confirmation/react.js +13 -167
- package/dist/components/data-table/react.js +59 -213
- package/dist/components/editable-text/react.js +14 -168
- package/dist/components/email-composer/react.js +25 -174
- package/dist/components/email-editor/react.js +34 -186
- package/dist/components/error-component/react.js +15 -169
- package/dist/components/icon-input/react.js +7 -161
- package/dist/components/image-crop-editor/react.js +19 -173
- package/dist/components/markdown/react.js +10 -164
- 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/react.js +9 -161
- package/dist/components/search-menu/react.js +11 -165
- package/dist/components/sidebar-layout/react.js +3 -157
- package/dist/components/support/react.js +14 -168
- package/dist/components/timezone-input/react.js +9 -163
- 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/services/agent/client/index.js +29 -183
- package/package.json +5 -1
|
@@ -1,161 +1,7 @@
|
|
|
1
1
|
// ../../src/components/presence-transition/react.tsx
|
|
2
|
-
import { Component as Component2, View
|
|
3
|
-
import { useLayoutEffect
|
|
4
|
-
|
|
5
|
-
// ../../src/lib/effect-ui-adapter/use-model.ts
|
|
6
|
-
import { MessageLog as MessageLog2 } from "effect/ui";
|
|
7
|
-
import {
|
|
8
|
-
createContext,
|
|
9
|
-
useCallback,
|
|
10
|
-
useContext,
|
|
11
|
-
useEffect,
|
|
12
|
-
useLayoutEffect,
|
|
13
|
-
useRef,
|
|
14
|
-
useState,
|
|
15
|
-
useSyncExternalStore
|
|
16
|
-
} from "react";
|
|
17
|
-
|
|
18
|
-
// ../../src/lib/effect-ui-adapter/model-runtime.ts
|
|
19
|
-
import { MessageLog, Renderer, View } from "effect/ui";
|
|
20
|
-
import { BrowserHost, Html } from "effect/ui/html";
|
|
21
|
-
import { Cause, Effect, Fiber } from "effect";
|
|
22
|
-
var node = () => ({ children: [] });
|
|
23
|
-
var modelHost = (commit) => {
|
|
24
|
-
const remove = (child) => {
|
|
25
|
-
if (!child.parent)
|
|
26
|
-
return;
|
|
27
|
-
child.parent.children.splice(child.parent.children.indexOf(child), 1);
|
|
28
|
-
delete child.parent;
|
|
29
|
-
};
|
|
30
|
-
return {
|
|
31
|
-
createElement: node,
|
|
32
|
-
createText: node,
|
|
33
|
-
setText: () => {},
|
|
34
|
-
setAttr: () => {},
|
|
35
|
-
setProp: () => {},
|
|
36
|
-
setEvents: () => {},
|
|
37
|
-
insertBefore: (parent, child, before) => {
|
|
38
|
-
if (child === before)
|
|
39
|
-
return;
|
|
40
|
-
remove(child);
|
|
41
|
-
const index = before ? parent.children.indexOf(before) : parent.children.length;
|
|
42
|
-
parent.children.splice(index, 0, child);
|
|
43
|
-
child.parent = parent;
|
|
44
|
-
},
|
|
45
|
-
remove,
|
|
46
|
-
parentOf: (child) => child.parent,
|
|
47
|
-
nextOf: (child) => child.parent?.children[child.parent.children.indexOf(child) + 1],
|
|
48
|
-
elements: ["html"],
|
|
49
|
-
controlled: new Set,
|
|
50
|
-
runsMounts: false,
|
|
51
|
-
commit
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
|
-
var mountModel = (component, props, publishSnapshot, messageLog, onEmit) => {
|
|
55
|
-
let currentProps = props;
|
|
56
|
-
let root;
|
|
57
|
-
let active = true;
|
|
58
|
-
let failure;
|
|
59
|
-
const publish = () => {
|
|
60
|
-
if (!active)
|
|
61
|
-
return;
|
|
62
|
-
if (failure) {
|
|
63
|
-
publishSnapshot({ error: failure });
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
const current = root?.model();
|
|
67
|
-
if (current !== undefined)
|
|
68
|
-
publishSnapshot({ model: current });
|
|
69
|
-
};
|
|
70
|
-
const fiber = Effect.runFork(Effect.scoped(Effect.gen(function* () {
|
|
71
|
-
const mounted = yield* Renderer.mount(component, Effect.succeed(props), node(), {
|
|
72
|
-
head: false,
|
|
73
|
-
onEmit,
|
|
74
|
-
fallback: ({ cause }) => {
|
|
75
|
-
failure = new Error("Effect UI root failed", {
|
|
76
|
-
cause: Cause.squash(cause)
|
|
77
|
-
});
|
|
78
|
-
return View.text("");
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
if (!active)
|
|
82
|
-
return;
|
|
83
|
-
root = mounted;
|
|
84
|
-
if (props !== currentProps)
|
|
85
|
-
mounted.setProps(currentProps);
|
|
86
|
-
publish();
|
|
87
|
-
return yield* Effect.never;
|
|
88
|
-
}).pipe(Effect.provide(Renderer.layer(modelHost(publish))), Effect.provideService(Html.Host, BrowserHost.htmlHost), Effect.provideService(MessageLog.MessageLog, messageLog))));
|
|
89
|
-
return {
|
|
90
|
-
send: (message) => {
|
|
91
|
-
root?.send(message);
|
|
92
|
-
publish();
|
|
93
|
-
},
|
|
94
|
-
setProps: (next) => {
|
|
95
|
-
currentProps = next;
|
|
96
|
-
root?.setProps(next);
|
|
97
|
-
},
|
|
98
|
-
dispose: () => {
|
|
99
|
-
active = false;
|
|
100
|
-
root = undefined;
|
|
101
|
-
Effect.runFork(Fiber.interrupt(fiber));
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
// ../../src/lib/effect-ui-adapter/use-model.ts
|
|
107
|
-
"use client";
|
|
108
|
-
var ModelMessageLogContext = createContext(undefined);
|
|
109
|
-
var useModel = (component, props, options = {}) => {
|
|
110
|
-
const contextLog = useContext(ModelMessageLogContext);
|
|
111
|
-
const messageLog = options.messageLog ?? (contextLog === undefined ? MessageLog2.noop : contextLog);
|
|
112
|
-
const [store] = useState(() => {
|
|
113
|
-
const initial = { model: component.init(props).model };
|
|
114
|
-
let snapshot = initial;
|
|
115
|
-
const listeners = new Set;
|
|
116
|
-
return {
|
|
117
|
-
subscribe: (listener) => {
|
|
118
|
-
listeners.add(listener);
|
|
119
|
-
return () => {
|
|
120
|
-
listeners.delete(listener);
|
|
121
|
-
};
|
|
122
|
-
},
|
|
123
|
-
getSnapshot: () => snapshot,
|
|
124
|
-
getServerSnapshot: () => initial,
|
|
125
|
-
publish: (next) => {
|
|
126
|
-
if ("model" in snapshot && "model" in next && Object.is(snapshot.model, next.model))
|
|
127
|
-
return;
|
|
128
|
-
if ("error" in snapshot && "error" in next && snapshot.error === next.error)
|
|
129
|
-
return;
|
|
130
|
-
snapshot = next;
|
|
131
|
-
listeners.forEach((listener) => listener());
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
});
|
|
135
|
-
const snapshot = useSyncExternalStore(store.subscribe, store.getSnapshot, store.getServerSnapshot);
|
|
136
|
-
const committed = useRef(props);
|
|
137
|
-
const onEmit = useRef(options.onEmit);
|
|
138
|
-
const runtime = useRef(undefined);
|
|
139
|
-
const send = useCallback((message) => runtime.current?.send(message), []);
|
|
140
|
-
useLayoutEffect(() => {
|
|
141
|
-
onEmit.current = options.onEmit;
|
|
142
|
-
committed.current = props;
|
|
143
|
-
runtime.current?.setProps(props);
|
|
144
|
-
}, [props, options.onEmit]);
|
|
145
|
-
useEffect(() => {
|
|
146
|
-
if (messageLog === null)
|
|
147
|
-
return;
|
|
148
|
-
const mounted = mountModel(component, committed.current, store.publish, messageLog, (event) => onEmit.current?.(event));
|
|
149
|
-
runtime.current = mounted;
|
|
150
|
-
return () => {
|
|
151
|
-
runtime.current = undefined;
|
|
152
|
-
mounted.dispose();
|
|
153
|
-
};
|
|
154
|
-
}, [component, messageLog, store]);
|
|
155
|
-
if ("error" in snapshot)
|
|
156
|
-
throw snapshot.error;
|
|
157
|
-
return { model: snapshot.model, send };
|
|
158
|
-
};
|
|
2
|
+
import { Component as Component2, View } from "effect/ui";
|
|
3
|
+
import { useLayoutEffect, useRef } from "react";
|
|
4
|
+
import { useModel } from "@krak-stack/registry/effect-ui-adapter/react";
|
|
159
5
|
|
|
160
6
|
// ../../src/components/presence-transition/index.ts
|
|
161
7
|
import { Schema as Schema2, Stream } from "effect";
|
|
@@ -251,7 +97,7 @@ var presenceMotion = (element, exited) => {
|
|
|
251
97
|
import { jsx } from "react/jsx-runtime";
|
|
252
98
|
var Model = Component2.define(presenceTransitionOptions).make({
|
|
253
99
|
...presenceTransitionBehaviours,
|
|
254
|
-
view: () =>
|
|
100
|
+
view: () => View.text("")
|
|
255
101
|
});
|
|
256
102
|
var PresenceTransition = ({
|
|
257
103
|
open,
|
|
@@ -260,11 +106,11 @@ var PresenceTransition = ({
|
|
|
260
106
|
className
|
|
261
107
|
}) => {
|
|
262
108
|
const { model, send } = useModel(Model, { open, duration });
|
|
263
|
-
const ref =
|
|
264
|
-
const controller =
|
|
265
|
-
const seen =
|
|
109
|
+
const ref = useRef(null);
|
|
110
|
+
const controller = useRef(undefined);
|
|
111
|
+
const seen = useRef(false);
|
|
266
112
|
const mounted = open || model.retained;
|
|
267
|
-
|
|
113
|
+
useLayoutEffect(() => {
|
|
268
114
|
if (!ref.current) {
|
|
269
115
|
seen.current = true;
|
|
270
116
|
return;
|
|
@@ -275,7 +121,7 @@ var PresenceTransition = ({
|
|
|
275
121
|
controller.current = undefined;
|
|
276
122
|
};
|
|
277
123
|
}, [mounted, send]);
|
|
278
|
-
|
|
124
|
+
useLayoutEffect(() => {
|
|
279
125
|
controller.current?.update(open, duration, open && seen.current);
|
|
280
126
|
seen.current = !open;
|
|
281
127
|
}, [open, duration]);
|
|
@@ -53,167 +53,13 @@ function Button({
|
|
|
53
53
|
import { Check, Copy, TriangleAlert } from "lucide-react";
|
|
54
54
|
import { Redacted as Redacted2 } from "effect";
|
|
55
55
|
import { Component as Component2 } from "effect/ui";
|
|
56
|
-
import { useLayoutEffect
|
|
56
|
+
import { useLayoutEffect, useRef, useState } from "react";
|
|
57
57
|
import { useKrakstackLocale } from "@krak-stack/registry/krakstack-provider/react";
|
|
58
|
-
|
|
59
|
-
// ../../src/lib/effect-ui-adapter/use-model.ts
|
|
60
|
-
import { MessageLog as MessageLog2 } from "effect/ui";
|
|
61
|
-
import {
|
|
62
|
-
createContext,
|
|
63
|
-
useCallback,
|
|
64
|
-
useContext,
|
|
65
|
-
useEffect,
|
|
66
|
-
useLayoutEffect,
|
|
67
|
-
useRef,
|
|
68
|
-
useState,
|
|
69
|
-
useSyncExternalStore
|
|
70
|
-
} from "react";
|
|
71
|
-
|
|
72
|
-
// ../../src/lib/effect-ui-adapter/model-runtime.ts
|
|
73
|
-
import { MessageLog, Renderer, View } from "effect/ui";
|
|
74
|
-
import { BrowserHost, Html } from "effect/ui/html";
|
|
75
|
-
import { Cause, Effect, Fiber } from "effect";
|
|
76
|
-
var node = () => ({ children: [] });
|
|
77
|
-
var modelHost = (commit) => {
|
|
78
|
-
const remove = (child) => {
|
|
79
|
-
if (!child.parent)
|
|
80
|
-
return;
|
|
81
|
-
child.parent.children.splice(child.parent.children.indexOf(child), 1);
|
|
82
|
-
delete child.parent;
|
|
83
|
-
};
|
|
84
|
-
return {
|
|
85
|
-
createElement: node,
|
|
86
|
-
createText: node,
|
|
87
|
-
setText: () => {},
|
|
88
|
-
setAttr: () => {},
|
|
89
|
-
setProp: () => {},
|
|
90
|
-
setEvents: () => {},
|
|
91
|
-
insertBefore: (parent, child, before) => {
|
|
92
|
-
if (child === before)
|
|
93
|
-
return;
|
|
94
|
-
remove(child);
|
|
95
|
-
const index = before ? parent.children.indexOf(before) : parent.children.length;
|
|
96
|
-
parent.children.splice(index, 0, child);
|
|
97
|
-
child.parent = parent;
|
|
98
|
-
},
|
|
99
|
-
remove,
|
|
100
|
-
parentOf: (child) => child.parent,
|
|
101
|
-
nextOf: (child) => child.parent?.children[child.parent.children.indexOf(child) + 1],
|
|
102
|
-
elements: ["html"],
|
|
103
|
-
controlled: new Set,
|
|
104
|
-
runsMounts: false,
|
|
105
|
-
commit
|
|
106
|
-
};
|
|
107
|
-
};
|
|
108
|
-
var mountModel = (component, props, publishSnapshot, messageLog, onEmit) => {
|
|
109
|
-
let currentProps = props;
|
|
110
|
-
let root;
|
|
111
|
-
let active = true;
|
|
112
|
-
let failure;
|
|
113
|
-
const publish = () => {
|
|
114
|
-
if (!active)
|
|
115
|
-
return;
|
|
116
|
-
if (failure) {
|
|
117
|
-
publishSnapshot({ error: failure });
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
const current = root?.model();
|
|
121
|
-
if (current !== undefined)
|
|
122
|
-
publishSnapshot({ model: current });
|
|
123
|
-
};
|
|
124
|
-
const fiber = Effect.runFork(Effect.scoped(Effect.gen(function* () {
|
|
125
|
-
const mounted = yield* Renderer.mount(component, Effect.succeed(props), node(), {
|
|
126
|
-
head: false,
|
|
127
|
-
onEmit,
|
|
128
|
-
fallback: ({ cause }) => {
|
|
129
|
-
failure = new Error("Effect UI root failed", {
|
|
130
|
-
cause: Cause.squash(cause)
|
|
131
|
-
});
|
|
132
|
-
return View.text("");
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
if (!active)
|
|
136
|
-
return;
|
|
137
|
-
root = mounted;
|
|
138
|
-
if (props !== currentProps)
|
|
139
|
-
mounted.setProps(currentProps);
|
|
140
|
-
publish();
|
|
141
|
-
return yield* Effect.never;
|
|
142
|
-
}).pipe(Effect.provide(Renderer.layer(modelHost(publish))), Effect.provideService(Html.Host, BrowserHost.htmlHost), Effect.provideService(MessageLog.MessageLog, messageLog))));
|
|
143
|
-
return {
|
|
144
|
-
send: (message) => {
|
|
145
|
-
root?.send(message);
|
|
146
|
-
publish();
|
|
147
|
-
},
|
|
148
|
-
setProps: (next) => {
|
|
149
|
-
currentProps = next;
|
|
150
|
-
root?.setProps(next);
|
|
151
|
-
},
|
|
152
|
-
dispose: () => {
|
|
153
|
-
active = false;
|
|
154
|
-
root = undefined;
|
|
155
|
-
Effect.runFork(Fiber.interrupt(fiber));
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
// ../../src/lib/effect-ui-adapter/use-model.ts
|
|
161
|
-
"use client";
|
|
162
|
-
var ModelMessageLogContext = createContext(undefined);
|
|
163
|
-
var useModel = (component, props, options = {}) => {
|
|
164
|
-
const contextLog = useContext(ModelMessageLogContext);
|
|
165
|
-
const messageLog = options.messageLog ?? (contextLog === undefined ? MessageLog2.noop : contextLog);
|
|
166
|
-
const [store] = useState(() => {
|
|
167
|
-
const initial = { model: component.init(props).model };
|
|
168
|
-
let snapshot = initial;
|
|
169
|
-
const listeners = new Set;
|
|
170
|
-
return {
|
|
171
|
-
subscribe: (listener) => {
|
|
172
|
-
listeners.add(listener);
|
|
173
|
-
return () => {
|
|
174
|
-
listeners.delete(listener);
|
|
175
|
-
};
|
|
176
|
-
},
|
|
177
|
-
getSnapshot: () => snapshot,
|
|
178
|
-
getServerSnapshot: () => initial,
|
|
179
|
-
publish: (next) => {
|
|
180
|
-
if ("model" in snapshot && "model" in next && Object.is(snapshot.model, next.model))
|
|
181
|
-
return;
|
|
182
|
-
if ("error" in snapshot && "error" in next && snapshot.error === next.error)
|
|
183
|
-
return;
|
|
184
|
-
snapshot = next;
|
|
185
|
-
listeners.forEach((listener) => listener());
|
|
186
|
-
}
|
|
187
|
-
};
|
|
188
|
-
});
|
|
189
|
-
const snapshot = useSyncExternalStore(store.subscribe, store.getSnapshot, store.getServerSnapshot);
|
|
190
|
-
const committed = useRef(props);
|
|
191
|
-
const onEmit = useRef(options.onEmit);
|
|
192
|
-
const runtime = useRef(undefined);
|
|
193
|
-
const send = useCallback((message) => runtime.current?.send(message), []);
|
|
194
|
-
useLayoutEffect(() => {
|
|
195
|
-
onEmit.current = options.onEmit;
|
|
196
|
-
committed.current = props;
|
|
197
|
-
runtime.current?.setProps(props);
|
|
198
|
-
}, [props, options.onEmit]);
|
|
199
|
-
useEffect(() => {
|
|
200
|
-
if (messageLog === null)
|
|
201
|
-
return;
|
|
202
|
-
const mounted = mountModel(component, committed.current, store.publish, messageLog, (event) => onEmit.current?.(event));
|
|
203
|
-
runtime.current = mounted;
|
|
204
|
-
return () => {
|
|
205
|
-
runtime.current = undefined;
|
|
206
|
-
mounted.dispose();
|
|
207
|
-
};
|
|
208
|
-
}, [component, messageLog, store]);
|
|
209
|
-
if ("error" in snapshot)
|
|
210
|
-
throw snapshot.error;
|
|
211
|
-
return { model: snapshot.model, send };
|
|
212
|
-
};
|
|
58
|
+
import { useModel } from "@krak-stack/registry/effect-ui-adapter/react";
|
|
213
59
|
|
|
214
60
|
// ../../src/components/copy-button/index.ts
|
|
215
|
-
import { Effect
|
|
216
|
-
import { Command, Component, UiSchema, View
|
|
61
|
+
import { Effect, Redacted, Schema as Schema2 } from "effect";
|
|
62
|
+
import { Command, Component, UiSchema, View } from "effect/ui";
|
|
217
63
|
|
|
218
64
|
// ../../src/components/copy-button/schema.ts
|
|
219
65
|
import { Schema } from "effect";
|
|
@@ -268,13 +114,13 @@ class WriteClipboard extends Command.Service()("copy-button/WriteClipboard", {
|
|
|
268
114
|
},
|
|
269
115
|
success: CopyButtonMessage
|
|
270
116
|
}) {
|
|
271
|
-
static layerFromWrite = (write) => WriteClipboard.toLayer(({ value }) =>
|
|
117
|
+
static layerFromWrite = (write) => WriteClipboard.toLayer(({ value }) => Effect.tryPromise(() => write(Redacted.value(value))).pipe(Effect.match({
|
|
272
118
|
onSuccess: () => CopyButtonMessage.Finished({ success: true }),
|
|
273
119
|
onFailure: () => CopyButtonMessage.Finished({ success: false })
|
|
274
120
|
})));
|
|
275
121
|
static browser = WriteClipboard.layerFromWrite((value) => navigator.clipboard.writeText(value));
|
|
276
122
|
}
|
|
277
|
-
var ResetClipboardFeedback = Command.make("copy-button/ResetFeedback", { args: { delay: Schema2.Number }, mode: "switch" }, ({ delay }) =>
|
|
123
|
+
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())));
|
|
278
124
|
var copyButtonOptions = {
|
|
279
125
|
name: "CopyButton",
|
|
280
126
|
props: CopyButtonModelProps,
|
|
@@ -296,7 +142,7 @@ var copyButtonBehaviours = {
|
|
|
296
142
|
};
|
|
297
143
|
var CopyButtonModel = Definition.make({
|
|
298
144
|
...copyButtonBehaviours,
|
|
299
|
-
view: () =>
|
|
145
|
+
view: () => View.text("")
|
|
300
146
|
});
|
|
301
147
|
var copyButtonStatus = (status, copy, description) => {
|
|
302
148
|
if (status === "idle")
|
|
@@ -324,19 +170,19 @@ function CopyButton({
|
|
|
324
170
|
}) {
|
|
325
171
|
const locale = useKrakstackLocale(localeOverride);
|
|
326
172
|
const labels = copyButtonMessages(locale, messages);
|
|
327
|
-
const callbacks =
|
|
173
|
+
const callbacks = useRef({
|
|
328
174
|
onCopied,
|
|
329
175
|
onCopyError,
|
|
330
176
|
failureLabel: labels.copyFailed
|
|
331
177
|
});
|
|
332
|
-
|
|
178
|
+
useLayoutEffect(() => {
|
|
333
179
|
callbacks.current = {
|
|
334
180
|
onCopied,
|
|
335
181
|
onCopyError,
|
|
336
182
|
failureLabel: labels.copyFailed
|
|
337
183
|
};
|
|
338
184
|
}, [onCopied, onCopyError, labels.copyFailed]);
|
|
339
|
-
const [component] =
|
|
185
|
+
const [component] = useState(() => CopyButtonModel.pipe(Component2.provide(WriteClipboard.layerFromWrite(async (text) => {
|
|
340
186
|
const { onCopied, onCopyError, failureLabel } = callbacks.current;
|
|
341
187
|
try {
|
|
342
188
|
await navigator.clipboard.writeText(text);
|
|
@@ -3,7 +3,7 @@ import { Schema as Schema6 } from "effect";
|
|
|
3
3
|
import { EditorContent, useEditor } from "@tiptap/react";
|
|
4
4
|
import { renderToReactElement } from "@tiptap/static-renderer/pm/react";
|
|
5
5
|
import {
|
|
6
|
-
useEffect
|
|
6
|
+
useEffect,
|
|
7
7
|
useEffectEvent,
|
|
8
8
|
useId
|
|
9
9
|
} from "react";
|
|
@@ -345,160 +345,8 @@ var richTextValidation = ({
|
|
|
345
345
|
]
|
|
346
346
|
});
|
|
347
347
|
|
|
348
|
-
// ../../src/
|
|
349
|
-
import {
|
|
350
|
-
import {
|
|
351
|
-
createContext,
|
|
352
|
-
useCallback,
|
|
353
|
-
useContext,
|
|
354
|
-
useEffect,
|
|
355
|
-
useLayoutEffect,
|
|
356
|
-
useRef,
|
|
357
|
-
useState,
|
|
358
|
-
useSyncExternalStore
|
|
359
|
-
} from "react";
|
|
360
|
-
|
|
361
|
-
// ../../src/lib/effect-ui-adapter/model-runtime.ts
|
|
362
|
-
import { MessageLog, Renderer, View } from "effect/ui";
|
|
363
|
-
import { BrowserHost, Html } from "effect/ui/html";
|
|
364
|
-
import { Cause, Effect, Fiber } from "effect";
|
|
365
|
-
var node = () => ({ children: [] });
|
|
366
|
-
var modelHost = (commit) => {
|
|
367
|
-
const remove = (child) => {
|
|
368
|
-
if (!child.parent)
|
|
369
|
-
return;
|
|
370
|
-
child.parent.children.splice(child.parent.children.indexOf(child), 1);
|
|
371
|
-
delete child.parent;
|
|
372
|
-
};
|
|
373
|
-
return {
|
|
374
|
-
createElement: node,
|
|
375
|
-
createText: node,
|
|
376
|
-
setText: () => {},
|
|
377
|
-
setAttr: () => {},
|
|
378
|
-
setProp: () => {},
|
|
379
|
-
setEvents: () => {},
|
|
380
|
-
insertBefore: (parent, child, before) => {
|
|
381
|
-
if (child === before)
|
|
382
|
-
return;
|
|
383
|
-
remove(child);
|
|
384
|
-
const index = before ? parent.children.indexOf(before) : parent.children.length;
|
|
385
|
-
parent.children.splice(index, 0, child);
|
|
386
|
-
child.parent = parent;
|
|
387
|
-
},
|
|
388
|
-
remove,
|
|
389
|
-
parentOf: (child) => child.parent,
|
|
390
|
-
nextOf: (child) => child.parent?.children[child.parent.children.indexOf(child) + 1],
|
|
391
|
-
elements: ["html"],
|
|
392
|
-
controlled: new Set,
|
|
393
|
-
runsMounts: false,
|
|
394
|
-
commit
|
|
395
|
-
};
|
|
396
|
-
};
|
|
397
|
-
var mountModel = (component, props, publishSnapshot, messageLog, onEmit) => {
|
|
398
|
-
let currentProps = props;
|
|
399
|
-
let root;
|
|
400
|
-
let active = true;
|
|
401
|
-
let failure;
|
|
402
|
-
const publish = () => {
|
|
403
|
-
if (!active)
|
|
404
|
-
return;
|
|
405
|
-
if (failure) {
|
|
406
|
-
publishSnapshot({ error: failure });
|
|
407
|
-
return;
|
|
408
|
-
}
|
|
409
|
-
const current = root?.model();
|
|
410
|
-
if (current !== undefined)
|
|
411
|
-
publishSnapshot({ model: current });
|
|
412
|
-
};
|
|
413
|
-
const fiber = Effect.runFork(Effect.scoped(Effect.gen(function* () {
|
|
414
|
-
const mounted = yield* Renderer.mount(component, Effect.succeed(props), node(), {
|
|
415
|
-
head: false,
|
|
416
|
-
onEmit,
|
|
417
|
-
fallback: ({ cause }) => {
|
|
418
|
-
failure = new Error("Effect UI root failed", {
|
|
419
|
-
cause: Cause.squash(cause)
|
|
420
|
-
});
|
|
421
|
-
return View.text("");
|
|
422
|
-
}
|
|
423
|
-
});
|
|
424
|
-
if (!active)
|
|
425
|
-
return;
|
|
426
|
-
root = mounted;
|
|
427
|
-
if (props !== currentProps)
|
|
428
|
-
mounted.setProps(currentProps);
|
|
429
|
-
publish();
|
|
430
|
-
return yield* Effect.never;
|
|
431
|
-
}).pipe(Effect.provide(Renderer.layer(modelHost(publish))), Effect.provideService(Html.Host, BrowserHost.htmlHost), Effect.provideService(MessageLog.MessageLog, messageLog))));
|
|
432
|
-
return {
|
|
433
|
-
send: (message) => {
|
|
434
|
-
root?.send(message);
|
|
435
|
-
publish();
|
|
436
|
-
},
|
|
437
|
-
setProps: (next) => {
|
|
438
|
-
currentProps = next;
|
|
439
|
-
root?.setProps(next);
|
|
440
|
-
},
|
|
441
|
-
dispose: () => {
|
|
442
|
-
active = false;
|
|
443
|
-
root = undefined;
|
|
444
|
-
Effect.runFork(Fiber.interrupt(fiber));
|
|
445
|
-
}
|
|
446
|
-
};
|
|
447
|
-
};
|
|
448
|
-
|
|
449
|
-
// ../../src/lib/effect-ui-adapter/use-model.ts
|
|
450
|
-
"use client";
|
|
451
|
-
var ModelMessageLogContext = createContext(undefined);
|
|
452
|
-
var useModel = (component, props, options = {}) => {
|
|
453
|
-
const contextLog = useContext(ModelMessageLogContext);
|
|
454
|
-
const messageLog = options.messageLog ?? (contextLog === undefined ? MessageLog2.noop : contextLog);
|
|
455
|
-
const [store] = useState(() => {
|
|
456
|
-
const initial = { model: component.init(props).model };
|
|
457
|
-
let snapshot = initial;
|
|
458
|
-
const listeners = new Set;
|
|
459
|
-
return {
|
|
460
|
-
subscribe: (listener) => {
|
|
461
|
-
listeners.add(listener);
|
|
462
|
-
return () => {
|
|
463
|
-
listeners.delete(listener);
|
|
464
|
-
};
|
|
465
|
-
},
|
|
466
|
-
getSnapshot: () => snapshot,
|
|
467
|
-
getServerSnapshot: () => initial,
|
|
468
|
-
publish: (next) => {
|
|
469
|
-
if ("model" in snapshot && "model" in next && Object.is(snapshot.model, next.model))
|
|
470
|
-
return;
|
|
471
|
-
if ("error" in snapshot && "error" in next && snapshot.error === next.error)
|
|
472
|
-
return;
|
|
473
|
-
snapshot = next;
|
|
474
|
-
listeners.forEach((listener) => listener());
|
|
475
|
-
}
|
|
476
|
-
};
|
|
477
|
-
});
|
|
478
|
-
const snapshot = useSyncExternalStore(store.subscribe, store.getSnapshot, store.getServerSnapshot);
|
|
479
|
-
const committed = useRef(props);
|
|
480
|
-
const onEmit = useRef(options.onEmit);
|
|
481
|
-
const runtime = useRef(undefined);
|
|
482
|
-
const send = useCallback((message) => runtime.current?.send(message), []);
|
|
483
|
-
useLayoutEffect(() => {
|
|
484
|
-
onEmit.current = options.onEmit;
|
|
485
|
-
committed.current = props;
|
|
486
|
-
runtime.current?.setProps(props);
|
|
487
|
-
}, [props, options.onEmit]);
|
|
488
|
-
useEffect(() => {
|
|
489
|
-
if (messageLog === null)
|
|
490
|
-
return;
|
|
491
|
-
const mounted = mountModel(component, committed.current, store.publish, messageLog, (event) => onEmit.current?.(event));
|
|
492
|
-
runtime.current = mounted;
|
|
493
|
-
return () => {
|
|
494
|
-
runtime.current = undefined;
|
|
495
|
-
mounted.dispose();
|
|
496
|
-
};
|
|
497
|
-
}, [component, messageLog, store]);
|
|
498
|
-
if ("error" in snapshot)
|
|
499
|
-
throw snapshot.error;
|
|
500
|
-
return { model: snapshot.model, send };
|
|
501
|
-
};
|
|
348
|
+
// ../../src/components/rich-text-editor/react.tsx
|
|
349
|
+
import { useModel } from "@krak-stack/registry/effect-ui-adapter/react";
|
|
502
350
|
|
|
503
351
|
// ../../src/components/rich-text-editor/classes.ts
|
|
504
352
|
var richTextEditorClasses = {
|
|
@@ -515,7 +363,7 @@ var resolveRichTextEditorClasses = (overrides) => ({
|
|
|
515
363
|
|
|
516
364
|
// ../../src/components/rich-text-editor/index.ts
|
|
517
365
|
import { Schema as Schema4 } from "effect";
|
|
518
|
-
import { Component, UiSchema, View
|
|
366
|
+
import { Component, UiSchema, View } from "effect/ui";
|
|
519
367
|
|
|
520
368
|
// ../../src/components/rich-text-editor/schema.ts
|
|
521
369
|
import { Schema as Schema3, Struct } from "effect";
|
|
@@ -745,7 +593,7 @@ var richTextEditorBehaviours = {
|
|
|
745
593
|
};
|
|
746
594
|
var RichTextEditorModel = Component.define(modelOptions).make({
|
|
747
595
|
...richTextEditorBehaviours,
|
|
748
|
-
view: () =>
|
|
596
|
+
view: () => View.text("")
|
|
749
597
|
});
|
|
750
598
|
|
|
751
599
|
// ../../src/components/rich-text-editor/engine.ts
|
|
@@ -944,15 +792,15 @@ var RichTextEditor = ({
|
|
|
944
792
|
editor?.view.focus();
|
|
945
793
|
return false;
|
|
946
794
|
};
|
|
947
|
-
|
|
795
|
+
useEffect(() => {
|
|
948
796
|
if (!editor)
|
|
949
797
|
return;
|
|
950
798
|
replaceRichText(editor, value);
|
|
951
799
|
}, [editor, value]);
|
|
952
|
-
|
|
800
|
+
useEffect(() => {
|
|
953
801
|
editor?.setEditable(!disabled, false);
|
|
954
802
|
}, [editor, disabled]);
|
|
955
|
-
|
|
803
|
+
useEffect(() => {
|
|
956
804
|
if (!editor)
|
|
957
805
|
return;
|
|
958
806
|
refreshMentionLabels(editor, variables);
|
|
@@ -961,7 +809,7 @@ var RichTextEditor = ({
|
|
|
961
809
|
if (editor)
|
|
962
810
|
runEditorAction(editor, action, variables);
|
|
963
811
|
});
|
|
964
|
-
|
|
812
|
+
useEffect(() => {
|
|
965
813
|
if (request)
|
|
966
814
|
applyAction(request.action);
|
|
967
815
|
}, [request]);
|