@samva/markup 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +17 -0
- package/dist/{ast-63I-VLQx.d.ts → ast-BLybiDxp.d.ts} +34 -60
- package/dist/ast.d.ts +2 -2
- package/dist/ast.js +4 -52
- package/dist/catalog-Db0UcCTg.d.ts +356 -0
- package/dist/{checks-DXuERO4B.js → checks-CmmITP6j.js} +14 -14
- package/dist/checks.d.ts +1 -1
- package/dist/checks.js +1 -1
- package/dist/classes.d.ts +1 -1
- package/dist/compile-sms.d.ts +3 -3
- package/dist/compile-whatsapp.d.ts +5 -5
- package/dist/compile-whatsapp.js +3 -3
- package/dist/compile.d.ts +5 -5
- package/dist/compile.js +5 -5
- package/dist/compiler.d.ts +4 -4
- package/dist/compiler.js +6 -6
- package/dist/components.d.ts +4 -4
- package/dist/conditionals.js +3 -3
- package/dist/corpus-CM7rKX41.d.ts +106 -0
- package/dist/{css-ar2lU3NC.d.ts → css-DoNc7CiC.d.ts} +4 -5
- package/dist/diagnostics-CqepLcpI.d.ts +47 -0
- package/dist/diagnostics-eFM9A_TU.d.ts +46 -0
- package/dist/diagnostics.d.ts +2 -2
- package/dist/diagnostics.js +15 -29
- package/dist/{elements-DtwKlFVH.d.ts → elements-ChJULZlh.d.ts} +40 -161
- package/dist/email/components.d.ts +1 -1
- package/dist/email/diagnostics.d.ts +1 -1
- package/dist/email/diagnostics.js +8 -43
- package/dist/email/elements.d.ts +1 -1
- package/dist/email/html.d.ts +2 -2
- package/dist/email/html.js +9 -9
- package/dist/email/jsx-dev-runtime.d.ts +3 -21
- package/dist/email/jsx-runtime.d.ts +1 -1
- package/dist/email/jsx-runtime.js +29 -3
- package/dist/email/render.d.ts +4 -4
- package/dist/email/render.js +1 -1
- package/dist/email/selection.d.ts +20 -31
- package/dist/email/selection.js +1 -53
- package/dist/email/source-edit.d.ts +1 -1
- package/dist/email/source-edit.js +2 -2
- package/dist/email/stylesheets.d.ts +1 -1
- package/dist/email/text.d.ts +1 -1
- package/dist/email/text.js +3 -3
- package/dist/emit.d.ts +2 -2
- package/dist/emit.js +5 -5
- package/dist/guards-eV1qLbf2.js +9 -0
- package/dist/{input-schema-BIfzI63B.d.ts → input-schema-7dPFVvNE.d.ts} +2 -2
- package/dist/input-schema-zjkgrXn2.js +455 -0
- package/dist/input-schema.d.ts +1 -1
- package/dist/input-schema.js +1 -169
- package/dist/interpolate.d.ts +9 -12
- package/dist/interpolate.js +1 -19
- package/dist/jsx-dev-runtime.d.ts +2 -2
- package/dist/{jsx-runtime-C5k_Zq0A.d.ts → jsx-runtime-BI4gI19E.d.ts} +3 -3
- package/dist/jsx-runtime.d.ts +1 -1
- package/dist/jsx-runtime.js +3 -3
- package/dist/model.d.ts +18 -33
- package/dist/model.js +4 -17
- package/dist/ops.d.ts +78 -172
- package/dist/ops.js +51 -117
- package/dist/{parser-CGBS73Gz.d.ts → parser-b_Kp5MT6.d.ts} +5 -5
- package/dist/parser.d.ts +1 -1
- package/dist/parser.js +8 -8
- package/dist/{predicate-G2SeSvoN.d.ts → predicate-Bmvgw7Ao.d.ts} +4 -4
- package/dist/{predicate-CvkzT-a2.js → predicate-DwXzmqIY.js} +11 -11
- package/dist/predicate.d.ts +1 -1
- package/dist/predicate.js +1 -1
- package/dist/presets/category-mapping.d.ts +1 -1
- package/dist/presets/corpus.d.ts +1 -1
- package/dist/presets/corpus.js +87 -140
- package/dist/presets/public-gallery.d.ts +106 -130
- package/dist/presets/public-gallery.js +131 -209
- package/dist/presets/public-handoff.d.ts +4 -4
- package/dist/presets/public-handoff.js +13 -11
- package/dist/presets/public-preview-artifacts.d.ts +5 -5
- package/dist/presets/public-preview-artifacts.js +9 -9
- package/dist/presets/public-preview.d.ts +0 -4
- package/dist/presets/public-preview.js +37 -362
- package/dist/presets/showcase.d.ts +2 -0
- package/dist/presets/showcase.js +627 -0
- package/dist/presets/sources.d.ts +1 -1
- package/dist/presets/sources.js +5767 -2023
- package/dist/presets.d.ts +2 -384
- package/dist/presets.js +299 -765
- package/dist/printer.d.ts +1 -1
- package/dist/{render-ykQhtMs_.js → render-T6IFPnP4.js} +12 -12
- package/dist/render-template.d.ts +7 -7
- package/dist/render-template.js +6 -6
- package/dist/showcase-dvJMn-Lo.d.ts +456 -0
- package/dist/{source-locations-BCJQnIfU.d.ts → source-locations-D6Te6Gy1.d.ts} +4 -26
- package/dist/source-locations.d.ts +2 -2
- package/dist/source-locations.js +3 -26
- package/dist/{template-Dy5yOPyp.d.ts → template-G-QPcfmn.d.ts} +4 -4
- package/dist/template.d.ts +1 -1
- package/dist/template.js +3 -3
- package/dist/theme-css.d.ts +3 -3
- package/dist/theme-css.js +3 -3
- package/dist/tsx-source-instrumentation.d.ts +1 -3
- package/dist/tsx-source-instrumentation.js +6 -6
- package/dist/tsx-tracer.d.ts +7 -11
- package/dist/tsx-tracer.js +164 -164
- package/dist/{variables-if1VrV34.d.ts → variables-BnKs1iqb.d.ts} +2 -2
- package/dist/variables.d.ts +1 -1
- package/dist/variables.js +4 -4
- package/package.json +8 -3
- package/dist/corpus-qrUD5O6r.d.ts +0 -254
- package/dist/diagnostics-Djd9ckLg.d.ts +0 -90
- package/dist/diagnostics-oveE-laV.d.ts +0 -79
package/dist/ops.js
CHANGED
|
@@ -1,82 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AttributeValueSchema, SML_TAGS, SmlNodeSchema, documentChannel } from "./ast.js";
|
|
1
|
+
import { documentChannel } from "./ast.js";
|
|
3
2
|
import { CHANNEL_TAG_SPECS, allowedChildren, parseSml } from "./parser.js";
|
|
4
3
|
import { compileSml } from "./compile.js";
|
|
5
|
-
import { a as isBreakingCompatibilityCheck, r as checkSmlCompatibility } from "./checks-
|
|
4
|
+
import { a as isBreakingCompatibilityCheck, r as checkSmlCompatibility } from "./checks-CmmITP6j.js";
|
|
6
5
|
import { printSml } from "./printer.js";
|
|
7
|
-
import { Result,
|
|
6
|
+
import { Result, TaggedError } from "better-result";
|
|
8
7
|
//#region src/ops.ts
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
nodeId: Schema.String,
|
|
16
|
-
name: Schema.String,
|
|
17
|
-
value: Schema.NullOr(AttributeValueSchema)
|
|
18
|
-
});
|
|
19
|
-
/**
|
|
20
|
-
* Replace a node's complete child list. The normal print → parse → compile
|
|
21
|
-
* preflight remains the authority on whether the replacement satisfies the
|
|
22
|
-
* target's content model.
|
|
23
|
-
*/
|
|
24
|
-
const SetChildrenOpSchema = Schema.TaggedStruct("setChildren", {
|
|
25
|
-
nodeId: Schema.String,
|
|
26
|
-
children: Schema.Array(SmlNodeSchema)
|
|
27
|
-
});
|
|
28
|
-
const InsertBlockOpSchema = Schema.TaggedStruct("insertBlock", {
|
|
29
|
-
tag: Schema.Literals(SML_TAGS),
|
|
30
|
-
referenceId: Schema.NullOr(Schema.String),
|
|
31
|
-
position: InsertPositionSchema
|
|
32
|
-
});
|
|
33
|
-
const InsertSnippetOpSchema = Schema.TaggedStruct("insertSnippet", {
|
|
34
|
-
snippet: Schema.String,
|
|
35
|
-
referenceId: Schema.NullOr(Schema.String),
|
|
36
|
-
position: InsertPositionSchema
|
|
37
|
-
});
|
|
38
|
-
/**
|
|
39
|
-
* `insertionIndex` is an element-child index into `targetParentId` evaluated
|
|
40
|
-
* AFTER the moved node has left its old position — the lifted-out model, so a
|
|
41
|
-
* same-parent caller must compute the index against the sibling list without
|
|
42
|
-
* the node. Indexes past the end append.
|
|
43
|
-
*/
|
|
44
|
-
const MoveNodeOpSchema = Schema.TaggedStruct("moveNode", {
|
|
45
|
-
nodeId: Schema.String,
|
|
46
|
-
targetParentId: Schema.String,
|
|
47
|
-
insertionIndex: Schema.Finite
|
|
48
|
-
});
|
|
49
|
-
const DuplicateNodeOpSchema = Schema.TaggedStruct("duplicateNode", { nodeId: Schema.String });
|
|
50
|
-
const RemoveNodeOpSchema = Schema.TaggedStruct("removeNode", { nodeId: Schema.String });
|
|
51
|
-
/**
|
|
52
|
-
* A single edit against SML source. `nodeId` (and `referenceId` /
|
|
53
|
-
* `targetParentId`) are positional ids from the source the caller last read;
|
|
54
|
-
* within a batch they always resolve against that snapshot — see {@link applyOps}.
|
|
55
|
-
*/
|
|
56
|
-
const SmlOpSchema = Schema.Union([
|
|
57
|
-
SetPropOpSchema,
|
|
58
|
-
SetChildrenOpSchema,
|
|
59
|
-
InsertBlockOpSchema,
|
|
60
|
-
InsertSnippetOpSchema,
|
|
61
|
-
MoveNodeOpSchema,
|
|
62
|
-
DuplicateNodeOpSchema,
|
|
63
|
-
RemoveNodeOpSchema
|
|
64
|
-
]);
|
|
65
|
-
const SmlOpResultSchema = Schema.Struct({
|
|
66
|
-
index: Schema.Finite,
|
|
67
|
-
status: Schema.Literals(["applied", "failed"]),
|
|
68
|
-
op: SmlOpSchema,
|
|
69
|
-
diagnostics: Schema.Array(DiagnosticSchema)
|
|
70
|
-
});
|
|
71
|
-
const ApplyOpsResultSchema = Schema.Struct({
|
|
72
|
-
source: Schema.String,
|
|
73
|
-
revision: Schema.String,
|
|
74
|
-
diagnostics: Schema.Array(DiagnosticSchema),
|
|
75
|
-
results: Schema.Array(SmlOpResultSchema)
|
|
76
|
-
});
|
|
77
|
-
var SmlOpError = class extends Schema.TaggedError()("SmlOpError", { diagnostics: Schema.Array(DiagnosticSchema) }) {
|
|
78
|
-
get message() {
|
|
79
|
-
return this.diagnostics.map((diagnostic) => diagnostic.message).join("\n");
|
|
8
|
+
var SmlOpError = class extends TaggedError("SmlOpError") {
|
|
9
|
+
constructor(args) {
|
|
10
|
+
super({
|
|
11
|
+
diagnostics: args.diagnostics,
|
|
12
|
+
message: args.diagnostics.map((diagnostic) => diagnostic.message).join("\n")
|
|
13
|
+
});
|
|
80
14
|
}
|
|
81
15
|
};
|
|
82
16
|
const zeroSpan = {
|
|
@@ -129,8 +63,8 @@ const sourceRevision = (source) => {
|
|
|
129
63
|
};
|
|
130
64
|
const normalizeSml = (source) => {
|
|
131
65
|
const parsed = parseSml(source);
|
|
132
|
-
if (Result.
|
|
133
|
-
return Result.
|
|
66
|
+
if (Result.isError(parsed)) return Result.err(parsed.error);
|
|
67
|
+
return Result.ok(printSml(parsed.value));
|
|
134
68
|
};
|
|
135
69
|
const findElement = (node, nodeId) => {
|
|
136
70
|
if (node.kind !== "element") return null;
|
|
@@ -150,8 +84,8 @@ const mapElement = (node, targetId, transform) => {
|
|
|
150
84
|
};
|
|
151
85
|
};
|
|
152
86
|
const transformElement = (document, targetId, transform) => {
|
|
153
|
-
if (findElement(document.root, targetId) === null) return Result.
|
|
154
|
-
return Result.
|
|
87
|
+
if (findElement(document.root, targetId) === null) return Result.err([diagnostic("op-target-not-found", `node "${targetId}" was not found in the current source`)]);
|
|
88
|
+
return Result.ok({
|
|
155
89
|
...document,
|
|
156
90
|
root: mapElement(document.root, targetId, transform)
|
|
157
91
|
});
|
|
@@ -294,10 +228,10 @@ const elementChildIndexToNodeIndex = (children, insertionIndex) => {
|
|
|
294
228
|
return children.length;
|
|
295
229
|
};
|
|
296
230
|
const insertChildren = (document, childrenToInsert, referenceId, position) => {
|
|
297
|
-
if (childrenToInsert.length === 0) return Result.
|
|
231
|
+
if (childrenToInsert.length === 0) return Result.err([diagnostic("op-empty-insert", "insert operation produced no element nodes")]);
|
|
298
232
|
if (referenceId === null || referenceId === document.root.id) {
|
|
299
233
|
const children = position === "before" ? [...childrenToInsert, ...document.root.children] : [...document.root.children, ...childrenToInsert];
|
|
300
|
-
return Result.
|
|
234
|
+
return Result.ok({
|
|
301
235
|
...document,
|
|
302
236
|
root: {
|
|
303
237
|
...document.root,
|
|
@@ -305,7 +239,7 @@ const insertChildren = (document, childrenToInsert, referenceId, position) => {
|
|
|
305
239
|
}
|
|
306
240
|
});
|
|
307
241
|
}
|
|
308
|
-
if (findElement(document.root, referenceId) === null) return Result.
|
|
242
|
+
if (findElement(document.root, referenceId) === null) return Result.err([diagnostic("op-target-not-found", `node "${referenceId}" was not found in the current source`)]);
|
|
309
243
|
if (position === "inside") return transformElement(document, referenceId, (element) => ({
|
|
310
244
|
...element,
|
|
311
245
|
children: [...element.children, ...childrenToInsert]
|
|
@@ -329,7 +263,7 @@ const insertChildren = (document, childrenToInsert, referenceId, position) => {
|
|
|
329
263
|
children: node.children.map(insertInParent)
|
|
330
264
|
};
|
|
331
265
|
};
|
|
332
|
-
return Result.
|
|
266
|
+
return Result.ok({
|
|
333
267
|
...document,
|
|
334
268
|
root: insertInParent(document.root)
|
|
335
269
|
});
|
|
@@ -338,13 +272,13 @@ const insertBlock = (document, op) => insertChildren(document, [makeBlock(op.tag
|
|
|
338
272
|
const insertSnippet = (document, op) => {
|
|
339
273
|
const rootTag = document.root.tag;
|
|
340
274
|
const parsed = parseSml(`<${rootTag}>${op.snippet}</${rootTag}>`);
|
|
341
|
-
if (Result.
|
|
342
|
-
const children = parsed.
|
|
275
|
+
if (Result.isError(parsed)) return Result.err(parsed.error.diagnostics);
|
|
276
|
+
const children = parsed.value.root.children.filter((child) => child.kind === "element");
|
|
343
277
|
return insertChildren(document, children, op.referenceId, op.position);
|
|
344
278
|
};
|
|
345
279
|
const removeNodeById = (document, nodeId) => {
|
|
346
|
-
if (document.root.id === nodeId) return Result.
|
|
347
|
-
if (findElement(document.root, nodeId) === null) return Result.
|
|
280
|
+
if (document.root.id === nodeId) return Result.err([diagnostic("op-root-target", "the document root cannot be removed")]);
|
|
281
|
+
if (findElement(document.root, nodeId) === null) return Result.err([diagnostic("op-target-not-found", `node "${nodeId}" was not found in the current source`)]);
|
|
348
282
|
const prune = (node) => {
|
|
349
283
|
if (node.kind !== "element") return node;
|
|
350
284
|
return {
|
|
@@ -352,7 +286,7 @@ const removeNodeById = (document, nodeId) => {
|
|
|
352
286
|
children: node.children.filter((child) => !(child.kind === "element" && child.id === nodeId)).map(prune)
|
|
353
287
|
};
|
|
354
288
|
};
|
|
355
|
-
return Result.
|
|
289
|
+
return Result.ok({
|
|
356
290
|
...document,
|
|
357
291
|
root: prune(document.root)
|
|
358
292
|
});
|
|
@@ -401,25 +335,25 @@ const insertIntoParent = (node, targetParentId, insertionIndex, moved) => {
|
|
|
401
335
|
};
|
|
402
336
|
};
|
|
403
337
|
const moveNode = (document, op) => {
|
|
404
|
-
if (document.root.id === op.nodeId) return Result.
|
|
338
|
+
if (document.root.id === op.nodeId) return Result.err([diagnostic("op-root-target", "the document root cannot be moved")]);
|
|
405
339
|
const moved = findElement(document.root, op.nodeId);
|
|
406
|
-
if (moved === null) return Result.
|
|
340
|
+
if (moved === null) return Result.err([diagnostic("op-target-not-found", `node "${op.nodeId}" was not found in the current source`)]);
|
|
407
341
|
const parent = findElement(document.root, op.targetParentId);
|
|
408
|
-
if (parent === null) return Result.
|
|
409
|
-
if (moved.id === parent.id || isDescendant(moved, parent.id)) return Result.
|
|
342
|
+
if (parent === null) return Result.err([diagnostic("op-target-not-found", `target parent "${op.targetParentId}" was not found in the current source`)]);
|
|
343
|
+
if (moved.id === parent.id || isDescendant(moved, parent.id)) return Result.err([diagnostic("op-invalid-reparent", "a node cannot be moved into itself or its descendants")]);
|
|
410
344
|
const channel = documentChannel(document);
|
|
411
345
|
const childModel = CHANNEL_TAG_SPECS[channel][parent.tag]?.content;
|
|
412
|
-
if (!(childModel === void 0 ? [] : allowedChildren(childModel)).includes(moved.tag)) return Result.
|
|
346
|
+
if (!(childModel === void 0 ? [] : allowedChildren(childModel)).includes(moved.tag)) return Result.err([diagnostic("op-invalid-reparent", `<${moved.tag}> is not allowed directly inside <${parent.tag}>`, parent.span)]);
|
|
413
347
|
const { node: rootWithoutMoved, removed } = removeElement(document.root, op.nodeId);
|
|
414
|
-
if (removed === null) return Result.
|
|
415
|
-
return Result.
|
|
348
|
+
if (removed === null) return Result.err([diagnostic("op-target-not-found", `node "${op.nodeId}" was not found in the current source`)]);
|
|
349
|
+
return Result.ok({
|
|
416
350
|
...document,
|
|
417
351
|
root: insertIntoParent(rootWithoutMoved, op.targetParentId, op.insertionIndex, removed)
|
|
418
352
|
});
|
|
419
353
|
};
|
|
420
354
|
const duplicateNode = (document, nodeId) => {
|
|
421
|
-
if (document.root.id === nodeId) return Result.
|
|
422
|
-
if (findElement(document.root, nodeId) === null) return Result.
|
|
355
|
+
if (document.root.id === nodeId) return Result.err([diagnostic("op-root-target", "the document root cannot be duplicated")]);
|
|
356
|
+
if (findElement(document.root, nodeId) === null) return Result.err([diagnostic("op-target-not-found", `node "${nodeId}" was not found in the current source`)]);
|
|
423
357
|
const insertClone = (node) => {
|
|
424
358
|
if (node.kind !== "element") return node;
|
|
425
359
|
const index = node.children.findIndex((child) => child.kind === "element" && child.id === nodeId);
|
|
@@ -439,13 +373,13 @@ const duplicateNode = (document, nodeId) => {
|
|
|
439
373
|
children: node.children.map(insertClone)
|
|
440
374
|
};
|
|
441
375
|
};
|
|
442
|
-
return Result.
|
|
376
|
+
return Result.ok({
|
|
443
377
|
...document,
|
|
444
378
|
root: insertClone(document.root)
|
|
445
379
|
});
|
|
446
380
|
};
|
|
447
381
|
const mutate = (document, op) => {
|
|
448
|
-
switch (op.
|
|
382
|
+
switch (op.type) {
|
|
449
383
|
case "setProp": return setProp(document, op);
|
|
450
384
|
case "setChildren": return setChildren(document, op);
|
|
451
385
|
case "insertBlock": return insertBlock(document, op);
|
|
@@ -457,12 +391,12 @@ const mutate = (document, op) => {
|
|
|
457
391
|
};
|
|
458
392
|
const preflight = (source) => {
|
|
459
393
|
const reparsed = parseSml(source);
|
|
460
|
-
if (Result.
|
|
461
|
-
const compiled = compileSml(reparsed.
|
|
462
|
-
if (Result.
|
|
394
|
+
if (Result.isError(reparsed)) return Result.err(reparsed.error.diagnostics);
|
|
395
|
+
const compiled = compileSml(reparsed.value);
|
|
396
|
+
if (Result.isError(compiled)) return Result.err(compiled.error.diagnostics);
|
|
463
397
|
const compatibilityErrors = checkSmlCompatibility({ source }).filter(isBreakingCompatibilityCheck).map((message) => diagnostic("compatibility-error", message));
|
|
464
|
-
if (compatibilityErrors.length > 0) return Result.
|
|
465
|
-
return Result.
|
|
398
|
+
if (compatibilityErrors.length > 0) return Result.err(compatibilityErrors);
|
|
399
|
+
return Result.ok(reparsed.value);
|
|
466
400
|
};
|
|
467
401
|
const failedResult = (index, op, diagnostics) => ({
|
|
468
402
|
index,
|
|
@@ -494,11 +428,11 @@ const failedResult = (index, op, diagnostics) => ({
|
|
|
494
428
|
*/
|
|
495
429
|
const applyOps = (source, ops, options) => {
|
|
496
430
|
const parsed = parseSml(source);
|
|
497
|
-
if (Result.
|
|
431
|
+
if (Result.isError(parsed)) return Result.err(new SmlOpError({ diagnostics: parsed.error.diagnostics }));
|
|
498
432
|
const currentRevision = String(options?.currentRevision ?? sourceRevision(source));
|
|
499
433
|
if (options?.expectedRevision !== void 0 && String(options.expectedRevision) !== currentRevision) {
|
|
500
434
|
const stale = diagnostic("stale-revision", `source revision changed from ${String(options.expectedRevision)} to ${currentRevision}`);
|
|
501
|
-
return Result.
|
|
435
|
+
return Result.ok({
|
|
502
436
|
source,
|
|
503
437
|
revision: currentRevision,
|
|
504
438
|
diagnostics: [stale],
|
|
@@ -506,25 +440,25 @@ const applyOps = (source, ops, options) => {
|
|
|
506
440
|
});
|
|
507
441
|
}
|
|
508
442
|
let currentSource = source;
|
|
509
|
-
let currentDocument = parsed.
|
|
443
|
+
let currentDocument = parsed.value;
|
|
510
444
|
const results = [];
|
|
511
445
|
const diagnostics = [];
|
|
512
446
|
ops.forEach((op, index) => {
|
|
513
447
|
const mutated = mutate(currentDocument, op);
|
|
514
|
-
if (Result.
|
|
515
|
-
results.push(failedResult(index, op, mutated.
|
|
516
|
-
diagnostics.push(...mutated.
|
|
448
|
+
if (Result.isError(mutated)) {
|
|
449
|
+
results.push(failedResult(index, op, mutated.error));
|
|
450
|
+
diagnostics.push(...mutated.error);
|
|
517
451
|
return;
|
|
518
452
|
}
|
|
519
|
-
const candidateSource = printSml(mutated.
|
|
453
|
+
const candidateSource = printSml(mutated.value);
|
|
520
454
|
const checked = preflight(candidateSource);
|
|
521
|
-
if (Result.
|
|
522
|
-
results.push(failedResult(index, op, checked.
|
|
523
|
-
diagnostics.push(...checked.
|
|
455
|
+
if (Result.isError(checked)) {
|
|
456
|
+
results.push(failedResult(index, op, checked.error));
|
|
457
|
+
diagnostics.push(...checked.error);
|
|
524
458
|
return;
|
|
525
459
|
}
|
|
526
460
|
currentSource = candidateSource;
|
|
527
|
-
currentDocument = mutated.
|
|
461
|
+
currentDocument = mutated.value;
|
|
528
462
|
results.push({
|
|
529
463
|
index,
|
|
530
464
|
status: "applied",
|
|
@@ -532,7 +466,7 @@ const applyOps = (source, ops, options) => {
|
|
|
532
466
|
diagnostics: []
|
|
533
467
|
});
|
|
534
468
|
});
|
|
535
|
-
return Result.
|
|
469
|
+
return Result.ok({
|
|
536
470
|
source: currentSource,
|
|
537
471
|
revision: sourceRevision(currentSource),
|
|
538
472
|
diagnostics,
|
|
@@ -541,6 +475,6 @@ const applyOps = (source, ops, options) => {
|
|
|
541
475
|
};
|
|
542
476
|
const applyOp = (source, op, options) => applyOps(source, [op], options);
|
|
543
477
|
//#endregion
|
|
544
|
-
export {
|
|
478
|
+
export { SmlOpError, applyOp, applyOps, normalizeSml, sourceRevision };
|
|
545
479
|
|
|
546
480
|
//# sourceMappingURL=ops.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { Result } from "
|
|
1
|
+
import { i as SmlParseError } from "./diagnostics-CqepLcpI.js";
|
|
2
|
+
import { S as SmlTag, b as SmlDocument, l as Channel } from "./ast-BLybiDxp.js";
|
|
3
|
+
import { Result } from "better-result";
|
|
4
4
|
//#region src/limits.d.ts
|
|
5
5
|
/** Hard ceilings shared by SML documents and standalone predicate parsing. */
|
|
6
6
|
declare const SML_PARSER_LIMITS: {
|
|
@@ -390,7 +390,7 @@ declare const UNIVERSAL_ATTRIBUTES: {
|
|
|
390
390
|
declare const UNIVERSAL_ATTRIBUTE_TAGS: ReadonlySet<SmlTag>;
|
|
391
391
|
/** Tags a content model admits as direct children (public alongside the spec tables). */
|
|
392
392
|
declare const allowedChildren: (model: ContentModel) => ReadonlyArray<SmlTag>;
|
|
393
|
-
declare const parseSml: (source: string) => Result
|
|
393
|
+
declare const parseSml: (source: string) => Result<SmlDocument, SmlParseError>;
|
|
394
394
|
//#endregion
|
|
395
395
|
export { SMS_TAG_SPECS as a, UNIVERSAL_ATTRIBUTE_TAGS as c, parseSml as d, SML_PARSER_LIMITS as f, EMAIL_TAG_SPECS as i, WHATSAPP_TAG_SPECS as l, CHANNEL_TAG_SPECS as n, TagSpec as o, ContentModel as r, UNIVERSAL_ATTRIBUTES as s, AttributeSpec as t, allowedChildren as u };
|
|
396
|
-
//# sourceMappingURL=parser-
|
|
396
|
+
//# sourceMappingURL=parser-b_Kp5MT6.d.ts.map
|
package/dist/parser.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as SMS_TAG_SPECS, c as UNIVERSAL_ATTRIBUTE_TAGS, d as parseSml, f as SML_PARSER_LIMITS, i as EMAIL_TAG_SPECS, l as WHATSAPP_TAG_SPECS, n as CHANNEL_TAG_SPECS, o as TagSpec, r as ContentModel, s as UNIVERSAL_ATTRIBUTES, t as AttributeSpec, u as allowedChildren } from "./parser-
|
|
1
|
+
import { a as SMS_TAG_SPECS, c as UNIVERSAL_ATTRIBUTE_TAGS, d as parseSml, f as SML_PARSER_LIMITS, i as EMAIL_TAG_SPECS, l as WHATSAPP_TAG_SPECS, n as CHANNEL_TAG_SPECS, o as TagSpec, r as ContentModel, s as UNIVERSAL_ATTRIBUTES, t as AttributeSpec, u as allowedChildren } from "./parser-b_Kp5MT6.js";
|
|
2
2
|
export { AttributeSpec, CHANNEL_TAG_SPECS, ContentModel, EMAIL_TAG_SPECS, SML_PARSER_LIMITS, SMS_TAG_SPECS, TagSpec, UNIVERSAL_ATTRIBUTES, UNIVERSAL_ATTRIBUTE_TAGS, WHATSAPP_TAG_SPECS, allowedChildren, parseSml };
|
package/dist/parser.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { SmlParseError } from "./diagnostics.js";
|
|
2
|
-
import { a as printPredicate, i as parsePredicate, o as SML_PARSER_LIMITS } from "./predicate-
|
|
2
|
+
import { a as printPredicate, i as parsePredicate, o as SML_PARSER_LIMITS } from "./predicate-DwXzmqIY.js";
|
|
3
3
|
import { CHANNEL_BY_ROOT_TAG, ROOT_TAGS, SML_TAGS, isRootTag } from "./ast.js";
|
|
4
4
|
import { TokenKind, createLexer } from "./lexer.js";
|
|
5
|
-
import { Result } from "
|
|
5
|
+
import { Result } from "better-result";
|
|
6
6
|
//#region src/parser.ts
|
|
7
|
-
const parserLimitFailure = (code, message, sourceLength) => Result.
|
|
7
|
+
const parserLimitFailure = (code, message, sourceLength) => Result.err(new SmlParseError({ diagnostics: [{
|
|
8
8
|
code,
|
|
9
9
|
message,
|
|
10
10
|
span: {
|
|
@@ -649,15 +649,15 @@ const parseSml = (source) => {
|
|
|
649
649
|
const testAttribute = element.attributes[testIndex];
|
|
650
650
|
if (testAttribute.value.kind === "string") {
|
|
651
651
|
const parsed = parsePredicate(testAttribute.value.value, testAttribute.valueSpan.start);
|
|
652
|
-
if (Result.
|
|
653
|
-
const first = parsed.
|
|
652
|
+
if (Result.isError(parsed)) {
|
|
653
|
+
const first = parsed.error[0];
|
|
654
654
|
return fail(first.code, first.message, first.span);
|
|
655
655
|
}
|
|
656
656
|
element.attributes[testIndex] = {
|
|
657
657
|
...testAttribute,
|
|
658
658
|
value: {
|
|
659
659
|
kind: "string",
|
|
660
|
-
value: printPredicate(parsed.
|
|
660
|
+
value: printPredicate(parsed.value)
|
|
661
661
|
}
|
|
662
662
|
};
|
|
663
663
|
}
|
|
@@ -815,7 +815,7 @@ const parseSml = (source) => {
|
|
|
815
815
|
root = null;
|
|
816
816
|
}
|
|
817
817
|
}
|
|
818
|
-
if (root === null || diagnostic !== void 0) return Result.
|
|
818
|
+
if (root === null || diagnostic !== void 0) return Result.err(new SmlParseError({ diagnostics: [diagnostic ?? {
|
|
819
819
|
code: "parse-failed",
|
|
820
820
|
message: "parse failed",
|
|
821
821
|
span: {
|
|
@@ -824,7 +824,7 @@ const parseSml = (source) => {
|
|
|
824
824
|
}
|
|
825
825
|
}] }));
|
|
826
826
|
assignNodeIds(root);
|
|
827
|
-
return Result.
|
|
827
|
+
return Result.ok({
|
|
828
828
|
kind: "document",
|
|
829
829
|
root
|
|
830
830
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Result } from "
|
|
1
|
+
import { a as Span, t as Diagnostic } from "./diagnostics-CqepLcpI.js";
|
|
2
|
+
import { Result } from "better-result";
|
|
3
3
|
//#region src/predicate.d.ts
|
|
4
4
|
/** Standalone predicates inherit the same source, nesting, and node ceilings as SML. */
|
|
5
5
|
declare const PREDICATE_PARSER_LIMITS: {
|
|
@@ -46,11 +46,11 @@ type PredicateAst = {
|
|
|
46
46
|
* predicate's first character (an <If> test attribute passes valueSpan.start),
|
|
47
47
|
* so diagnostic and node spans point into the containing document.
|
|
48
48
|
*/
|
|
49
|
-
declare const parsePredicate: (source: string, baseOffset?: number) => Result
|
|
49
|
+
declare const parsePredicate: (source: string, baseOffset?: number) => Result<PredicateAst, ReadonlyArray<Diagnostic>>;
|
|
50
50
|
declare const evaluatePredicate: (ast: PredicateAst, variables: Record<string, unknown>) => boolean;
|
|
51
51
|
/** Canonical form: single space around operators/keywords, minimal parens. */
|
|
52
52
|
declare const printPredicate: (ast: PredicateAst) => string;
|
|
53
53
|
declare const collectPredicateVariables: (ast: PredicateAst) => Set<string>;
|
|
54
54
|
//#endregion
|
|
55
55
|
export { collectPredicateVariables as a, printPredicate as c, PredicateLiteral as i, PREDICATE_PARSER_LIMITS as n, evaluatePredicate as o, PredicateAst as r, parsePredicate as s, ComparisonOp as t };
|
|
56
|
-
//# sourceMappingURL=predicate-
|
|
56
|
+
//# sourceMappingURL=predicate-Bmvgw7Ao.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Result } from "
|
|
1
|
+
import { Result } from "better-result";
|
|
2
2
|
//#region src/limits.ts
|
|
3
3
|
/** Hard ceilings shared by SML documents and standalone predicate parsing. */
|
|
4
4
|
const SML_PARSER_LIMITS = {
|
|
@@ -46,7 +46,7 @@ const tokenize = (source, baseOffset) => {
|
|
|
46
46
|
const tokens = [];
|
|
47
47
|
let index = 0;
|
|
48
48
|
const length = source.length;
|
|
49
|
-
const failAt = (code, message, start, end) => Result.
|
|
49
|
+
const failAt = (code, message, start, end) => Result.err({ diagnostic: {
|
|
50
50
|
code,
|
|
51
51
|
message,
|
|
52
52
|
span: {
|
|
@@ -175,7 +175,7 @@ const tokenize = (source, baseOffset) => {
|
|
|
175
175
|
end: baseOffset + length
|
|
176
176
|
}
|
|
177
177
|
});
|
|
178
|
-
return Result.
|
|
178
|
+
return Result.ok(tokens);
|
|
179
179
|
};
|
|
180
180
|
const COMPARISON_OPS = [
|
|
181
181
|
"==",
|
|
@@ -191,7 +191,7 @@ const COMPARISON_OPS = [
|
|
|
191
191
|
* so diagnostic and node spans point into the containing document.
|
|
192
192
|
*/
|
|
193
193
|
const parsePredicate = (source, baseOffset = 0) => {
|
|
194
|
-
if (source.length > SML_PARSER_LIMITS.maxCharacters) return Result.
|
|
194
|
+
if (source.length > SML_PARSER_LIMITS.maxCharacters) return Result.err([{
|
|
195
195
|
code: "predicate-character-limit",
|
|
196
196
|
message: `predicate exceeds the ${SML_PARSER_LIMITS.maxCharacters} character limit`,
|
|
197
197
|
span: {
|
|
@@ -199,7 +199,7 @@ const parsePredicate = (source, baseOffset = 0) => {
|
|
|
199
199
|
end: baseOffset + source.length
|
|
200
200
|
}
|
|
201
201
|
}]);
|
|
202
|
-
if (new TextEncoder().encode(source).byteLength > SML_PARSER_LIMITS.maxUtf8Bytes) return Result.
|
|
202
|
+
if (new TextEncoder().encode(source).byteLength > SML_PARSER_LIMITS.maxUtf8Bytes) return Result.err([{
|
|
203
203
|
code: "predicate-byte-limit",
|
|
204
204
|
message: `predicate exceeds the ${SML_PARSER_LIMITS.maxUtf8Bytes} byte UTF-8 limit`,
|
|
205
205
|
span: {
|
|
@@ -208,8 +208,8 @@ const parsePredicate = (source, baseOffset = 0) => {
|
|
|
208
208
|
}
|
|
209
209
|
}]);
|
|
210
210
|
const lexed = tokenize(source, baseOffset);
|
|
211
|
-
if (Result.
|
|
212
|
-
const tokens = lexed.
|
|
211
|
+
if (Result.isError(lexed)) return Result.err([lexed.error.diagnostic]);
|
|
212
|
+
const tokens = lexed.value;
|
|
213
213
|
let index = 0;
|
|
214
214
|
let diagnostic;
|
|
215
215
|
let nodeCount = 0;
|
|
@@ -334,7 +334,7 @@ const parsePredicate = (source, baseOffset = 0) => {
|
|
|
334
334
|
}
|
|
335
335
|
return left;
|
|
336
336
|
};
|
|
337
|
-
if (source.trim().length === 0) return Result.
|
|
337
|
+
if (source.trim().length === 0) return Result.err([{
|
|
338
338
|
code: "predicate-empty",
|
|
339
339
|
message: "empty predicate — write e.g. plan == 'pro'",
|
|
340
340
|
span: {
|
|
@@ -347,7 +347,7 @@ const parsePredicate = (source, baseOffset = 0) => {
|
|
|
347
347
|
const trailing = peek();
|
|
348
348
|
if (trailing.kind !== "eof") fail("predicate-trailing-input", `unexpected ${JSON.stringify(trailing.text)} after the predicate — join clauses with "and" or "or"`, trailing.span);
|
|
349
349
|
}
|
|
350
|
-
if (ast === null || diagnostic !== void 0) return Result.
|
|
350
|
+
if (ast === null || diagnostic !== void 0) return Result.err([diagnostic ?? {
|
|
351
351
|
code: "predicate-parse-failed",
|
|
352
352
|
message: "predicate parse failed",
|
|
353
353
|
span: {
|
|
@@ -355,7 +355,7 @@ const parsePredicate = (source, baseOffset = 0) => {
|
|
|
355
355
|
end: baseOffset + source.length
|
|
356
356
|
}
|
|
357
357
|
}]);
|
|
358
|
-
return Result.
|
|
358
|
+
return Result.ok(ast);
|
|
359
359
|
};
|
|
360
360
|
const toNumber = (value) => {
|
|
361
361
|
if (typeof value === "number") return value;
|
|
@@ -536,4 +536,4 @@ const collectPredicateVariables = (ast) => {
|
|
|
536
536
|
//#endregion
|
|
537
537
|
export { printPredicate as a, parsePredicate as i, collectPredicateVariables as n, SML_PARSER_LIMITS as o, evaluatePredicate as r, PREDICATE_PARSER_LIMITS as t };
|
|
538
538
|
|
|
539
|
-
//# sourceMappingURL=predicate-
|
|
539
|
+
//# sourceMappingURL=predicate-DwXzmqIY.js.map
|
package/dist/predicate.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as collectPredicateVariables, c as printPredicate, i as PredicateLiteral, n as PREDICATE_PARSER_LIMITS, o as evaluatePredicate, r as PredicateAst, s as parsePredicate, t as ComparisonOp } from "./predicate-
|
|
1
|
+
import { a as collectPredicateVariables, c as printPredicate, i as PredicateLiteral, n as PREDICATE_PARSER_LIMITS, o as evaluatePredicate, r as PredicateAst, s as parsePredicate, t as ComparisonOp } from "./predicate-Bmvgw7Ao.js";
|
|
2
2
|
export { ComparisonOp, PREDICATE_PARSER_LIMITS, PredicateAst, PredicateLiteral, collectPredicateVariables, evaluatePredicate, parsePredicate, printPredicate };
|
package/dist/predicate.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as printPredicate, i as parsePredicate, n as collectPredicateVariables, r as evaluatePredicate, t as PREDICATE_PARSER_LIMITS } from "./predicate-
|
|
1
|
+
import { a as printPredicate, i as parsePredicate, n as collectPredicateVariables, r as evaluatePredicate, t as PREDICATE_PARSER_LIMITS } from "./predicate-DwXzmqIY.js";
|
|
2
2
|
export { PREDICATE_PARSER_LIMITS, collectPredicateVariables, evaluatePredicate, parsePredicate, printPredicate };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PresetCategory } from "../
|
|
1
|
+
import { r as PresetCategory } from "../catalog-Db0UcCTg.js";
|
|
2
2
|
import { TemplateCollectionId } from "./public-gallery.js";
|
|
3
3
|
//#region presets/category-mapping.d.ts
|
|
4
4
|
declare const LAB_DIMENSIONS: readonly ["newsletter", "receipt", "security", "product-update", "onboarding", "promotion", "shipping", "social-notification"];
|
package/dist/presets/corpus.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as PublicCorpusRegistrationIssue, c as TemplateFacetQuery, d as matchesTemplateFacets, f as ownedPresetSourcePath, h as templateFacetOptions, i as PublicCorpusRegistration, l as TemplateFacetSet, m as registerPublicCorpusEntry, n as InspirationReference, o as TemplateCorpusKind, p as ownedShowcasePresetSources, r as OwnedEditablePreset, s as TemplateCorpusRecord, t as BrandRecreationPreset, u as brandRecreationProvenance } from "../corpus-
|
|
1
|
+
import { a as PublicCorpusRegistrationIssue, c as TemplateFacetQuery, d as matchesTemplateFacets, f as ownedPresetSourcePath, h as templateFacetOptions, i as PublicCorpusRegistration, l as TemplateFacetSet, m as registerPublicCorpusEntry, n as InspirationReference, o as TemplateCorpusKind, p as ownedShowcasePresetSources, r as OwnedEditablePreset, s as TemplateCorpusRecord, t as BrandRecreationPreset, u as brandRecreationProvenance } from "../corpus-CM7rKX41.js";
|
|
2
2
|
export { BrandRecreationPreset, InspirationReference, OwnedEditablePreset, PublicCorpusRegistration, PublicCorpusRegistrationIssue, TemplateCorpusKind, TemplateCorpusRecord, TemplateFacetQuery, TemplateFacetSet, brandRecreationProvenance, matchesTemplateFacets, ownedPresetSourcePath, ownedShowcasePresetSources, registerPublicCorpusEntry, templateFacetOptions };
|