@krak-stack/registry 0.10.5 → 0.10.7
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 +20 -0
- package/dist/components/ui/animated-list.d.ts +6 -7
- package/dist/components/ui/animated-list.js +329 -139
- package/dist/components/ui/animated-number.js +47 -24
- package/dist/components/ui/auto-height.js +56 -15
- package/dist/components/ui/email-editor.d.ts +124 -0
- package/dist/components/ui/email-editor.js +2677 -0
- package/dist/components/ui/form.d.ts +5 -5
- package/dist/components/ui/presence-transition.d.ts +1 -1
- package/dist/components/ui/presence-transition.js +79 -26
- package/dist/components/ui/rich-text-editor.d.ts +70 -0
- package/dist/components/ui/rich-text-editor.js +1135 -0
- package/dist/components/ui/time-picker.d.ts +13 -4
- package/dist/components/ui/time-picker.js +141 -47
- package/dist/components/ui/time-picker.schema.d.ts +16 -2
- package/dist/lib/email-document/model.d.ts +26 -0
- package/dist/lib/email-document/model.js +253 -0
- package/dist/lib/email-document/render.d.ts +115 -0
- package/dist/lib/email-document/render.js +469 -0
- package/dist/lib/email-document/schema.d.ts +285 -0
- package/dist/lib/email-document/schema.js +139 -0
- package/dist/lib/krakmotion.d.ts +27 -0
- package/dist/lib/rich-text/dom.d.ts +40 -0
- package/dist/lib/rich-text/model.d.ts +19 -0
- package/dist/lib/rich-text/model.js +141 -0
- package/dist/lib/rich-text/schema.d.ts +64 -0
- package/dist/lib/rich-text/schema.js +53 -0
- package/package.json +29 -5
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
// ../../src/lib/email-document/model.ts
|
|
2
|
+
import { Schema as Schema4 } from "effect";
|
|
3
|
+
|
|
4
|
+
// ../../src/lib/rich-text/schema.ts
|
|
5
|
+
import { Schema } from "effect";
|
|
6
|
+
var RichTextLink = Schema.String.check(Schema.isMaxLength(2000), Schema.makeFilter((value) => {
|
|
7
|
+
if (/[\s\p{Cc}\\{}]/u.test(value))
|
|
8
|
+
return false;
|
|
9
|
+
const url = URL.parse(value);
|
|
10
|
+
return url !== null && ["https:", "mailto:"].includes(url.protocol) && !url.username && !url.password;
|
|
11
|
+
})).annotate({ identifier: "RichTextLink" });
|
|
12
|
+
var RichTextMarks = Schema.Struct({
|
|
13
|
+
bold: Schema.optional(Schema.Boolean),
|
|
14
|
+
italic: Schema.optional(Schema.Boolean),
|
|
15
|
+
underline: Schema.optional(Schema.Boolean),
|
|
16
|
+
href: Schema.optional(RichTextLink)
|
|
17
|
+
}).annotate({ identifier: "RichTextMarks" });
|
|
18
|
+
var RichTextInline = Schema.Union([
|
|
19
|
+
Schema.Struct({
|
|
20
|
+
type: Schema.Literal("text"),
|
|
21
|
+
text: Schema.String.check(Schema.isMaxLength(20000)),
|
|
22
|
+
marks: Schema.optional(RichTextMarks)
|
|
23
|
+
}),
|
|
24
|
+
Schema.Struct({
|
|
25
|
+
type: Schema.Literal("variable"),
|
|
26
|
+
key: Schema.String.check(Schema.isPattern(/^[a-zA-Z][a-zA-Z0-9_.]{0,79}$/)),
|
|
27
|
+
marks: Schema.optional(RichTextMarks)
|
|
28
|
+
})
|
|
29
|
+
]).annotate({ identifier: "RichTextInline" });
|
|
30
|
+
var RichTextBlockKind = Schema.Literals([
|
|
31
|
+
"paragraph",
|
|
32
|
+
"heading",
|
|
33
|
+
"bullet",
|
|
34
|
+
"numbered"
|
|
35
|
+
]).annotate({ identifier: "RichTextBlockKind" });
|
|
36
|
+
var RichTextDocument = Schema.Struct({
|
|
37
|
+
version: Schema.Literal(1),
|
|
38
|
+
blocks: Schema.Array(Schema.Struct({
|
|
39
|
+
type: RichTextBlockKind,
|
|
40
|
+
content: Schema.Array(RichTextInline).check(Schema.isMaxLength(2000))
|
|
41
|
+
})).check(Schema.isMinLength(1), Schema.isMaxLength(100))
|
|
42
|
+
}).check(Schema.makeFilter((value) => value.blocks.reduce((size, block) => size + block.content.reduce((count, inline) => count + (inline.type === "text" ? inline.text.length : 1), 0), 0) <= 20000)).annotate({ identifier: "RichTextDocument" });
|
|
43
|
+
var RichTextVariable = Schema.Struct({
|
|
44
|
+
key: Schema.String.check(Schema.isPattern(/^[a-zA-Z][a-zA-Z0-9_.]{0,79}$/)),
|
|
45
|
+
label: Schema.String,
|
|
46
|
+
type: Schema.Literals(["text", "url"]),
|
|
47
|
+
sample: Schema.String
|
|
48
|
+
}).annotate({ identifier: "RichTextVariable" });
|
|
49
|
+
|
|
50
|
+
// ../../src/lib/rich-text/model.ts
|
|
51
|
+
import { Schema as Schema2 } from "effect";
|
|
52
|
+
var sameMarks = Schema2.toEquivalence(RichTextMarks);
|
|
53
|
+
var richTextFromString = (text) => ({
|
|
54
|
+
version: 1,
|
|
55
|
+
blocks: text.split(/\r\n?|\n/).map((line) => ({
|
|
56
|
+
type: "paragraph",
|
|
57
|
+
content: line ? [{ type: "text", text: line }] : []
|
|
58
|
+
}))
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// ../../src/lib/email-document/schema.ts
|
|
62
|
+
import { Schema as Schema3 } from "effect";
|
|
63
|
+
var EmailImageUrl = RichTextLink.check(Schema3.isPattern(/^https:\/\//)).annotate({ identifier: "EmailImageUrl" });
|
|
64
|
+
var EmailColor = Schema3.String.check(Schema3.isPattern(/^#[0-9a-fA-F]{6}$/)).annotate({ identifier: "EmailColor" });
|
|
65
|
+
var EmailAlignment = Schema3.Literals([
|
|
66
|
+
"left",
|
|
67
|
+
"center",
|
|
68
|
+
"right"
|
|
69
|
+
]).annotate({ identifier: "EmailAlignment" });
|
|
70
|
+
var EmailFont = Schema3.Literals(["sans", "serif", "mono"]).annotate({
|
|
71
|
+
identifier: "EmailFont"
|
|
72
|
+
});
|
|
73
|
+
var spacing = Schema3.Int.check(Schema3.isBetween({ minimum: 0, maximum: 96 }));
|
|
74
|
+
var common = {
|
|
75
|
+
id: Schema3.NonEmptyString.check(Schema3.isMaxLength(80)),
|
|
76
|
+
alignment: EmailAlignment,
|
|
77
|
+
paddingTop: spacing,
|
|
78
|
+
paddingBottom: spacing
|
|
79
|
+
};
|
|
80
|
+
var EmailDestination = Schema3.Union([
|
|
81
|
+
Schema3.Struct({ type: Schema3.Literal("url"), url: RichTextLink }),
|
|
82
|
+
Schema3.Struct({
|
|
83
|
+
type: Schema3.Literal("variable"),
|
|
84
|
+
key: RichTextVariable.fields.key
|
|
85
|
+
})
|
|
86
|
+
]).annotate({ identifier: "EmailDestination" });
|
|
87
|
+
var EmailElement = Schema3.Union([
|
|
88
|
+
Schema3.Struct({
|
|
89
|
+
...common,
|
|
90
|
+
type: Schema3.Literal("text"),
|
|
91
|
+
content: RichTextDocument
|
|
92
|
+
}),
|
|
93
|
+
Schema3.Struct({
|
|
94
|
+
...common,
|
|
95
|
+
type: Schema3.Literal("button"),
|
|
96
|
+
label: Schema3.String.check(Schema3.isMaxLength(200)),
|
|
97
|
+
destination: EmailDestination
|
|
98
|
+
}),
|
|
99
|
+
Schema3.Struct({
|
|
100
|
+
...common,
|
|
101
|
+
type: Schema3.Literal("code"),
|
|
102
|
+
variable: RichTextVariable.fields.key
|
|
103
|
+
}),
|
|
104
|
+
Schema3.Struct({
|
|
105
|
+
...common,
|
|
106
|
+
type: Schema3.Literals(["logo", "image"]),
|
|
107
|
+
src: EmailImageUrl,
|
|
108
|
+
alt: Schema3.String.check(Schema3.isMaxLength(200)),
|
|
109
|
+
width: Schema3.Int.check(Schema3.isBetween({ minimum: 32, maximum: 560 }))
|
|
110
|
+
}),
|
|
111
|
+
Schema3.Struct({ ...common, type: Schema3.Literal("divider") }),
|
|
112
|
+
Schema3.Struct({ ...common, type: Schema3.Literal("spacer"), height: spacing })
|
|
113
|
+
]).annotate({ identifier: "EmailElement" });
|
|
114
|
+
var subject = Schema3.String.check(Schema3.isMaxLength(200), Schema3.isPattern(/^[^\r\n]*$/));
|
|
115
|
+
var EmailDocument = Schema3.Struct({
|
|
116
|
+
version: Schema3.Literal(1),
|
|
117
|
+
subject,
|
|
118
|
+
preview: subject,
|
|
119
|
+
appearance: Schema3.Struct({
|
|
120
|
+
background: EmailColor,
|
|
121
|
+
surface: EmailColor,
|
|
122
|
+
text: EmailColor,
|
|
123
|
+
primary: EmailColor,
|
|
124
|
+
primaryText: EmailColor,
|
|
125
|
+
font: EmailFont,
|
|
126
|
+
radius: Schema3.Int.check(Schema3.isBetween({ minimum: 0, maximum: 32 }))
|
|
127
|
+
}),
|
|
128
|
+
elements: Schema3.Array(EmailElement).check(Schema3.isMaxLength(40))
|
|
129
|
+
}).check(Schema3.makeFilter((document) => new Set(document.elements.map((element) => element.id)).size === document.elements.length)).annotate({ identifier: "EmailDocument" });
|
|
130
|
+
var EmailRenderInput = Schema3.Struct({
|
|
131
|
+
document: EmailDocument,
|
|
132
|
+
variables: Schema3.Array(RichTextVariable),
|
|
133
|
+
values: Schema3.Record(Schema3.String, Schema3.String),
|
|
134
|
+
requiredVariables: Schema3.optional(Schema3.Array(Schema3.String))
|
|
135
|
+
}).annotate({ identifier: "EmailRenderInput" });
|
|
136
|
+
var EmailRenderResult = Schema3.Struct({
|
|
137
|
+
subject: Schema3.String,
|
|
138
|
+
html: Schema3.String,
|
|
139
|
+
text: Schema3.String
|
|
140
|
+
}).annotate({ identifier: "EmailRenderResult" });
|
|
141
|
+
|
|
142
|
+
// ../../src/lib/email-document/model.ts
|
|
143
|
+
var emailElementTypes = [
|
|
144
|
+
"text",
|
|
145
|
+
"button",
|
|
146
|
+
"code",
|
|
147
|
+
"logo",
|
|
148
|
+
"image",
|
|
149
|
+
"divider",
|
|
150
|
+
"spacer"
|
|
151
|
+
];
|
|
152
|
+
var newEmailElement = (type, input) => {
|
|
153
|
+
const common = {
|
|
154
|
+
id: input.id,
|
|
155
|
+
alignment: "left",
|
|
156
|
+
paddingTop: 8,
|
|
157
|
+
paddingBottom: 8
|
|
158
|
+
};
|
|
159
|
+
switch (type) {
|
|
160
|
+
case "text":
|
|
161
|
+
return { ...common, type, content: richTextFromString(input.text) };
|
|
162
|
+
case "button":
|
|
163
|
+
return {
|
|
164
|
+
...common,
|
|
165
|
+
type,
|
|
166
|
+
label: input.button,
|
|
167
|
+
destination: input.urlVariable ? { type: "variable", key: input.urlVariable } : { type: "url", url: "https://example.com" }
|
|
168
|
+
};
|
|
169
|
+
case "code":
|
|
170
|
+
return { ...common, type, variable: input.codeVariable ?? "code" };
|
|
171
|
+
case "logo":
|
|
172
|
+
case "image":
|
|
173
|
+
return {
|
|
174
|
+
...common,
|
|
175
|
+
type,
|
|
176
|
+
src: "https://krakstack.net/favicon.svg",
|
|
177
|
+
alt: input.imageAlt,
|
|
178
|
+
width: type === "logo" ? 48 : 160
|
|
179
|
+
};
|
|
180
|
+
case "divider":
|
|
181
|
+
return { ...common, type };
|
|
182
|
+
case "spacer":
|
|
183
|
+
return { ...common, type, height: 24 };
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
var interpolateEmailText = (text, values) => text.replace(/\{\{([a-zA-Z][a-zA-Z0-9_.]*)\}\}/g, (token, key) => values[key] ?? token);
|
|
187
|
+
var richTextFromEmailText = (text) => ({
|
|
188
|
+
version: 1,
|
|
189
|
+
blocks: [
|
|
190
|
+
{
|
|
191
|
+
type: "paragraph",
|
|
192
|
+
content: text.split(/(\{\{[a-zA-Z][a-zA-Z0-9_.]*\}\})/g).filter(Boolean).map((part) => /^\{\{[a-zA-Z][a-zA-Z0-9_.]*\}\}$/.test(part) ? { type: "variable", key: part.slice(2, -2) } : { type: "text", text: part })
|
|
193
|
+
}
|
|
194
|
+
]
|
|
195
|
+
});
|
|
196
|
+
var textReferences = (text) => [...text.matchAll(/\{\{([a-zA-Z][a-zA-Z0-9_.]*)\}\}/g)].map((match) => match[1] ?? "");
|
|
197
|
+
var emailDocumentReferences = (document) => [
|
|
198
|
+
...new Set([
|
|
199
|
+
...textReferences(document.subject),
|
|
200
|
+
...textReferences(document.preview),
|
|
201
|
+
...document.elements.flatMap((element) => {
|
|
202
|
+
switch (element.type) {
|
|
203
|
+
case "text":
|
|
204
|
+
return element.content.blocks.flatMap((block) => block.content.flatMap((inline) => inline.type === "variable" ? [inline.key] : []));
|
|
205
|
+
case "code":
|
|
206
|
+
return [element.variable];
|
|
207
|
+
case "button":
|
|
208
|
+
return [
|
|
209
|
+
...textReferences(element.label),
|
|
210
|
+
...element.destination.type === "variable" ? [element.destination.key] : []
|
|
211
|
+
];
|
|
212
|
+
default:
|
|
213
|
+
return [];
|
|
214
|
+
}
|
|
215
|
+
})
|
|
216
|
+
])
|
|
217
|
+
];
|
|
218
|
+
var validateEmailDocument = ({
|
|
219
|
+
document,
|
|
220
|
+
variables,
|
|
221
|
+
values,
|
|
222
|
+
requiredVariables = []
|
|
223
|
+
}) => {
|
|
224
|
+
if (!Schema4.is(EmailDocument)(document))
|
|
225
|
+
return [{ code: "invalid-document" }];
|
|
226
|
+
const references = emailDocumentReferences(document);
|
|
227
|
+
const issues = [];
|
|
228
|
+
for (const key of references) {
|
|
229
|
+
if (!variables.some((variable) => variable.key === key))
|
|
230
|
+
issues.push({ code: "unknown-variable", key });
|
|
231
|
+
if (values && !values[key])
|
|
232
|
+
issues.push({ code: "missing-variable", key });
|
|
233
|
+
}
|
|
234
|
+
for (const element of document.elements) {
|
|
235
|
+
if (element.type === "button" && element.destination.type === "variable") {
|
|
236
|
+
const key = element.destination.key;
|
|
237
|
+
if (variables.find((variable) => variable.key === key)?.type !== "url" || values && !Schema4.is(RichTextLink)(values[key]))
|
|
238
|
+
issues.push({ code: "invalid-url", key });
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
for (const key of requiredVariables)
|
|
242
|
+
if (!document.elements.some((element) => element.type === "code" && element.variable === key || element.type === "button" && element.destination.type === "variable" && element.destination.key === key || element.type === "text" && element.content.blocks.some((block) => block.content.some((inline) => inline.type === "variable" && inline.key === key))))
|
|
243
|
+
issues.push({ code: "missing-required-variable", key });
|
|
244
|
+
return issues;
|
|
245
|
+
};
|
|
246
|
+
export {
|
|
247
|
+
emailDocumentReferences,
|
|
248
|
+
emailElementTypes,
|
|
249
|
+
interpolateEmailText,
|
|
250
|
+
newEmailElement,
|
|
251
|
+
richTextFromEmailText,
|
|
252
|
+
validateEmailDocument
|
|
253
|
+
};
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
declare const EmailDocumentRenderError_base: Schema.Class<EmailDocumentRenderError, Schema.TaggedStruct<"EmailDocumentRenderError", {
|
|
3
|
+
readonly reason: Schema.String;
|
|
4
|
+
}>, import("effect/Cause").YieldableError & {
|
|
5
|
+
readonly brand: unique symbol;
|
|
6
|
+
}>;
|
|
7
|
+
export declare class EmailDocumentRenderError extends EmailDocumentRenderError_base {
|
|
8
|
+
}
|
|
9
|
+
/** The same validated document produces HTML and plain text; no executable templates. */
|
|
10
|
+
export declare const renderEmailDocument: (input: {
|
|
11
|
+
readonly document: {
|
|
12
|
+
readonly version: 1;
|
|
13
|
+
readonly subject: string;
|
|
14
|
+
readonly preview: string;
|
|
15
|
+
readonly appearance: {
|
|
16
|
+
readonly background: string;
|
|
17
|
+
readonly surface: string;
|
|
18
|
+
readonly text: string;
|
|
19
|
+
readonly primary: string;
|
|
20
|
+
readonly primaryText: string;
|
|
21
|
+
readonly font: "mono" | "sans" | "serif";
|
|
22
|
+
readonly radius: number;
|
|
23
|
+
};
|
|
24
|
+
readonly elements: readonly ({
|
|
25
|
+
readonly id: string;
|
|
26
|
+
readonly alignment: "center" | "left" | "right";
|
|
27
|
+
readonly paddingTop: number;
|
|
28
|
+
readonly paddingBottom: number;
|
|
29
|
+
readonly type: "text";
|
|
30
|
+
readonly content: {
|
|
31
|
+
readonly version: 1;
|
|
32
|
+
readonly blocks: readonly {
|
|
33
|
+
readonly type: "bullet" | "heading" | "numbered" | "paragraph";
|
|
34
|
+
readonly content: readonly ({
|
|
35
|
+
readonly type: "text";
|
|
36
|
+
readonly text: string;
|
|
37
|
+
readonly marks?: {
|
|
38
|
+
readonly bold?: boolean | undefined;
|
|
39
|
+
readonly italic?: boolean | undefined;
|
|
40
|
+
readonly underline?: boolean | undefined;
|
|
41
|
+
readonly href?: string | undefined;
|
|
42
|
+
} | undefined;
|
|
43
|
+
} | {
|
|
44
|
+
readonly type: "variable";
|
|
45
|
+
readonly key: string;
|
|
46
|
+
readonly marks?: {
|
|
47
|
+
readonly bold?: boolean | undefined;
|
|
48
|
+
readonly italic?: boolean | undefined;
|
|
49
|
+
readonly underline?: boolean | undefined;
|
|
50
|
+
readonly href?: string | undefined;
|
|
51
|
+
} | undefined;
|
|
52
|
+
})[];
|
|
53
|
+
}[];
|
|
54
|
+
};
|
|
55
|
+
} | {
|
|
56
|
+
readonly id: string;
|
|
57
|
+
readonly alignment: "center" | "left" | "right";
|
|
58
|
+
readonly paddingTop: number;
|
|
59
|
+
readonly paddingBottom: number;
|
|
60
|
+
readonly type: "button";
|
|
61
|
+
readonly label: string;
|
|
62
|
+
readonly destination: {
|
|
63
|
+
readonly type: "url";
|
|
64
|
+
readonly url: string;
|
|
65
|
+
} | {
|
|
66
|
+
readonly type: "variable";
|
|
67
|
+
readonly key: string;
|
|
68
|
+
};
|
|
69
|
+
} | {
|
|
70
|
+
readonly id: string;
|
|
71
|
+
readonly alignment: "center" | "left" | "right";
|
|
72
|
+
readonly paddingTop: number;
|
|
73
|
+
readonly paddingBottom: number;
|
|
74
|
+
readonly type: "code";
|
|
75
|
+
readonly variable: string;
|
|
76
|
+
} | {
|
|
77
|
+
readonly id: string;
|
|
78
|
+
readonly alignment: "center" | "left" | "right";
|
|
79
|
+
readonly paddingTop: number;
|
|
80
|
+
readonly paddingBottom: number;
|
|
81
|
+
readonly type: "image" | "logo";
|
|
82
|
+
readonly src: string;
|
|
83
|
+
readonly alt: string;
|
|
84
|
+
readonly width: number;
|
|
85
|
+
} | {
|
|
86
|
+
readonly id: string;
|
|
87
|
+
readonly alignment: "center" | "left" | "right";
|
|
88
|
+
readonly paddingTop: number;
|
|
89
|
+
readonly paddingBottom: number;
|
|
90
|
+
readonly type: "divider";
|
|
91
|
+
} | {
|
|
92
|
+
readonly id: string;
|
|
93
|
+
readonly alignment: "center" | "left" | "right";
|
|
94
|
+
readonly paddingTop: number;
|
|
95
|
+
readonly paddingBottom: number;
|
|
96
|
+
readonly type: "spacer";
|
|
97
|
+
readonly height: number;
|
|
98
|
+
})[];
|
|
99
|
+
};
|
|
100
|
+
readonly variables: readonly {
|
|
101
|
+
readonly key: string;
|
|
102
|
+
readonly label: string;
|
|
103
|
+
readonly type: "text" | "url";
|
|
104
|
+
readonly sample: string;
|
|
105
|
+
}[];
|
|
106
|
+
readonly values: {
|
|
107
|
+
readonly [x: string]: string;
|
|
108
|
+
};
|
|
109
|
+
readonly requiredVariables?: readonly string[] | undefined;
|
|
110
|
+
}) => Effect.Effect<{
|
|
111
|
+
subject: string;
|
|
112
|
+
html: string;
|
|
113
|
+
text: string;
|
|
114
|
+
}, EmailDocumentRenderError, never>;
|
|
115
|
+
export {};
|