@perkyzz/emvb 1.1.0 → 1.2.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/THIRD_PARTY_NOTICES.md +1 -0
- package/package.json +10 -9
- package/src/admin/agents-api.ts +5 -1
- package/src/admin/content-api.ts +29 -0
- package/src/admin/editor/Editor.tsx +6 -1
- package/src/admin/editor/ScheduleDialog.tsx +167 -0
- package/src/admin/editor/TopBar.tsx +33 -1
- package/src/admin/editor/dnd/new-element.ts +46 -0
- package/src/admin/editor/editor-chrome.tsx +9 -0
- package/src/admin/editor/element-chrome.ts +22 -0
- package/src/admin/editor/panels/ElementPanel.tsx +5 -1
- package/src/admin/editor/panels/settings/DraftTextField.tsx +33 -1
- package/src/admin/editor/panels/settings/FieldBindControl.tsx +6 -1
- package/src/admin/editor/panels/settings/FieldControl.tsx +10 -1
- package/src/admin/editor/panels/settings/IconPicker.tsx +4 -1
- package/src/admin/editor/panels/settings/ItemList.tsx +36 -2
- package/src/admin/editor/panels/settings/advanced-rules.ts +3 -0
- package/src/admin/editor/store.ts +7 -1
- package/src/admin/editor/useEditorData.ts +4 -0
- package/src/admin/editor/useSave.ts +47 -3
- package/src/admin/export-api.ts +20 -3
- package/src/admin/menus-api.ts +113 -0
- package/src/admin/pages/ImportElementorDialog.tsx +25 -1
- package/src/astro/EmVBPage.astro +3 -0
- package/src/astro/render.ts +43 -18
- package/src/astro/request-data.ts +3 -0
- package/src/astro/resolve-theme.ts +77 -44
- package/src/astro/visitor.ts +23 -4
- package/src/astro/widgets/EmVBAlertsRuntime.astro +8 -0
- package/src/astro/widgets/EmVBCarouselRuntime.astro +8 -0
- package/src/astro/widgets/EmVBLightboxRuntime.astro +8 -0
- package/src/astro/widgets/EmVBWidgetRuntimes.astro +19 -0
- package/src/astro/widgets/alerts.ts +37 -0
- package/src/astro/widgets/carousel.ts +167 -0
- package/src/astro/widgets/index.ts +1 -0
- package/src/astro/widgets/lightbox.ts +123 -0
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +101 -2
- package/src/core/arrange.ts +57 -1
- package/src/core/bounded-array.ts +16 -13
- package/src/core/contract.ts +4 -1
- package/src/core/elements/icon-svg.ts +135 -0
- package/src/core/elements/index.ts +33 -127
- package/src/core/elements/widgets.ts +907 -0
- package/src/core/export/runtimes.generated.ts +3 -0
- package/src/core/export/site.ts +20 -3
- package/src/core/extensions/schema.ts +2 -1
- package/src/core/geo-trust.ts +18 -0
- package/src/core/icons/social.generated.ts +29 -0
- package/src/core/image-edit/schema.ts +2 -1
- package/src/core/import/elementor/context.ts +18 -0
- package/src/core/import/elementor/index.ts +50 -7
- package/src/core/import/elementor/widgets.ts +394 -133
- package/src/core/issue-cap.ts +19 -0
- package/src/core/limits.ts +6 -0
- package/src/core/loop-collections.ts +33 -0
- package/src/core/proposals.ts +8 -2
- package/src/core/render/index.ts +27 -4
- package/src/core/render/vnode.ts +44 -6
- package/src/core/sanitize/svg-upload.ts +276 -23
- package/src/core/sanitize/svg.ts +3 -3
- package/src/core/schema/descriptors.ts +4 -0
- package/src/core/schema/design.ts +6 -5
- package/src/core/schema/layout.ts +395 -15
- package/src/core/schema/style.ts +2 -1
- package/src/core/shadowing-ids.ts +41 -0
- package/src/core/theme/conditions.ts +2 -1
- package/src/core/theme/parse-doc.ts +10 -5
- package/src/core/theme/triggers.ts +3 -2
- package/src/core/validate.ts +3 -2
- package/src/index.ts +23 -2
- package/src/mcp/ports.ts +18 -7
- package/src/mcp/proposals.ts +36 -11
- package/src/mcp/tools.ts +1 -1
- package/src/server/agent-settings.ts +12 -1
- package/src/server/hooks.ts +41 -6
- package/src/server/mcp-routes.ts +11 -5
- package/src/server/plugin.ts +27 -2
- package/src/server/presence.ts +5 -1
- package/src/server/proposals.ts +16 -4
- package/src/server/requests.ts +60 -11
- package/src/server/site-origin.ts +13 -0
- package/src/server/targets.ts +26 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { boundedArray } from "../bounded-array.ts";
|
|
1
2
|
import { z } from "zod";
|
|
2
3
|
import { LIST_MARKERS } from "../css-keywords.ts";
|
|
3
4
|
import { MAX_TEXT_LENGTH } from "../limits.ts";
|
|
@@ -41,7 +42,7 @@ export const CONTRACT_VERSION = "1.0";
|
|
|
41
42
|
export const NodeId = z
|
|
42
43
|
.string()
|
|
43
44
|
.regex(/^[A-Za-z0-9_-]{4,24}$/, "Ids are 4-24 letters, digits, _ or -");
|
|
44
|
-
const ClassIds =
|
|
45
|
+
const ClassIds = boundedArray(z.string().regex(/^[a-z0-9-]{1,40}$/), 20);
|
|
45
46
|
/** CSS id attribute (Advanced). Letters first; unique on the page (checked in validateLayout). */
|
|
46
47
|
const HtmlId = z
|
|
47
48
|
.string()
|
|
@@ -76,7 +77,7 @@ const HtmlAttribute = z.strictObject({
|
|
|
76
77
|
value: z.string().max(200),
|
|
77
78
|
});
|
|
78
79
|
|
|
79
|
-
const HtmlAttributes =
|
|
80
|
+
const HtmlAttributes = boundedArray(HtmlAttribute, 20);
|
|
80
81
|
|
|
81
82
|
/** Where a bound field reads its live value (W-307). */
|
|
82
83
|
export const BIND_SOURCES = ["post", "site", "param"] as const;
|
|
@@ -140,14 +141,14 @@ export const Audience = z.strictObject({
|
|
|
140
141
|
.min(1)
|
|
141
142
|
.max(50)
|
|
142
143
|
.optional(),
|
|
143
|
-
devices:
|
|
144
|
+
devices: boundedArray(z.enum(AUDIENCE_DEVICES), 3, 1).optional(),
|
|
144
145
|
visitor: z.enum(["new", "returning"]).optional(),
|
|
145
146
|
/** From hour `from` up to (not including) hour `to`, 0–24; wraps past midnight when to < from. */
|
|
146
147
|
hours: z
|
|
147
148
|
.strictObject({ from: z.number().int().min(0).max(23), to: z.number().int().min(0).max(24) })
|
|
148
149
|
.optional(),
|
|
149
150
|
/** Days of the week, 0 = Sunday. */
|
|
150
|
-
days:
|
|
151
|
+
days: boundedArray(z.number().int().min(0).max(6), 7, 1).optional(),
|
|
151
152
|
/** IANA time zone for hours and days, e.g. America/Toronto. Unset = UTC. */
|
|
152
153
|
timeZone: z
|
|
153
154
|
.string()
|
|
@@ -158,7 +159,7 @@ export const Audience = z.strictObject({
|
|
|
158
159
|
* Visitor segments the host passes (W-329), e.g. `member`, `plan:pro`: the rule matches a
|
|
159
160
|
* visitor in any of them. A letter or digit, then letters, digits, `:`, `_` or `-`, up to 64.
|
|
160
161
|
*/
|
|
161
|
-
segments:
|
|
162
|
+
segments: boundedArray(z.string().regex(AUDIENCE_SEGMENT, SEGMENT_HINT), 20, 1).optional(),
|
|
162
163
|
hide: z.boolean().optional(),
|
|
163
164
|
});
|
|
164
165
|
export type Audience = z.infer<typeof Audience>;
|
|
@@ -218,7 +219,7 @@ const parentNode = <T extends string, P extends z.ZodType>(type: T, props: P) =>
|
|
|
218
219
|
z.strictObject({
|
|
219
220
|
...nodeFields(type, props),
|
|
220
221
|
get children(): z.ZodType<LayoutNode[]> {
|
|
221
|
-
return
|
|
222
|
+
return ChildList;
|
|
222
223
|
},
|
|
223
224
|
});
|
|
224
225
|
|
|
@@ -240,7 +241,7 @@ export const TextMark = z.strictObject({
|
|
|
240
241
|
newTab: z.literal(true).optional(),
|
|
241
242
|
});
|
|
242
243
|
export type TextMark = z.infer<typeof TextMark>;
|
|
243
|
-
const TextMarks =
|
|
244
|
+
const TextMarks = boundedArray(TextMark, MAX_TEXT_MARKS);
|
|
244
245
|
|
|
245
246
|
export const HeadingNode = leafNode(
|
|
246
247
|
"heading",
|
|
@@ -313,7 +314,7 @@ export const ListNode = leafNode(
|
|
|
313
314
|
marker: z.enum(LIST_MARKERS).optional(),
|
|
314
315
|
/** W-952: the first number of a numbered list. */
|
|
315
316
|
start: z.number().int().min(1).max(9999).optional(),
|
|
316
|
-
items:
|
|
317
|
+
items: boundedArray(z.string().max(MAX_TEXT_LENGTH), 200),
|
|
317
318
|
}),
|
|
318
319
|
);
|
|
319
320
|
|
|
@@ -445,7 +446,7 @@ export const FlexboxNode = parentNode("flexbox", z.strictObject({ ...BoxLink }))
|
|
|
445
446
|
*/
|
|
446
447
|
const GRID_TRACK =
|
|
447
448
|
/^(?:1fr|2fr|3fr|auto|min-content|max-content|0|(?:\d+(?:\.\d+)?)(?:px|rem|em|%|vw|vh|ch))$/;
|
|
448
|
-
const GridTracks =
|
|
449
|
+
const GridTracks = boundedArray(z.string().regex(GRID_TRACK), 12, 1);
|
|
449
450
|
|
|
450
451
|
export const GridNode = parentNode(
|
|
451
452
|
"grid",
|
|
@@ -770,6 +771,17 @@ export const KNOWN_ELEMENT_TYPES = [
|
|
|
770
771
|
"layout-section",
|
|
771
772
|
"toc",
|
|
772
773
|
"language-switcher",
|
|
774
|
+
"rating",
|
|
775
|
+
"alert",
|
|
776
|
+
"icon-box",
|
|
777
|
+
"image-box",
|
|
778
|
+
"testimonial",
|
|
779
|
+
"social-icons",
|
|
780
|
+
"social-link",
|
|
781
|
+
"gallery",
|
|
782
|
+
"gallery-image",
|
|
783
|
+
"carousel",
|
|
784
|
+
"carousel-slide",
|
|
773
785
|
] as const;
|
|
774
786
|
|
|
775
787
|
/** Headings on this page, as a list of links. No script (W-345). */
|
|
@@ -791,6 +803,251 @@ export const LanguageSwitcherNode = leafNode(
|
|
|
791
803
|
}),
|
|
792
804
|
);
|
|
793
805
|
|
|
806
|
+
/** W-1023: most stars a Rating shows. */
|
|
807
|
+
export const MAX_RATING = 10;
|
|
808
|
+
|
|
809
|
+
/**
|
|
810
|
+
* W-1023: a star rating, `value` out of `max` (5 when unset), in steps as fine as a tenth. Screen
|
|
811
|
+
* readers hear `label` with {value} and {max} filled in; unset it says "Rated 4.5 out of 5".
|
|
812
|
+
* A value above `max` shows as `max`, so lowering the number of stars never makes a page invalid.
|
|
813
|
+
*/
|
|
814
|
+
export const RatingNode = leafNode(
|
|
815
|
+
"rating",
|
|
816
|
+
z.strictObject({
|
|
817
|
+
value: z.number().min(0).max(MAX_RATING),
|
|
818
|
+
max: z.number().int().min(1).max(MAX_RATING).optional(),
|
|
819
|
+
label: z.string().max(120).optional(),
|
|
820
|
+
/** Each star's width and height in px. Unset = 20. */
|
|
821
|
+
size: z.number().int().min(8).max(128).optional(),
|
|
822
|
+
}),
|
|
823
|
+
);
|
|
824
|
+
|
|
825
|
+
/** W-1025: the kinds of Alert, each with its own colours and icon. */
|
|
826
|
+
export const ALERT_VARIANTS = ["info", "success", "warning", "danger"] as const;
|
|
827
|
+
|
|
828
|
+
/**
|
|
829
|
+
* W-1025: a notice: an optional title and text in the variant's colours, with its icon unless
|
|
830
|
+
* `hideIcon`. `dismissible` adds a close button that the opt-in alerts runtime shows and wires;
|
|
831
|
+
* without that script the notice simply stays.
|
|
832
|
+
*/
|
|
833
|
+
export const AlertNode = leafNode(
|
|
834
|
+
"alert",
|
|
835
|
+
z.strictObject({
|
|
836
|
+
variant: z.enum(ALERT_VARIANTS),
|
|
837
|
+
title: z.string().max(200).optional(),
|
|
838
|
+
text: z.string().max(MAX_TEXT_LENGTH),
|
|
839
|
+
hideIcon: z.boolean().optional(),
|
|
840
|
+
dismissible: z.boolean().optional(),
|
|
841
|
+
/** The close button's name for screen readers. Unset = "Dismiss". */
|
|
842
|
+
dismissLabel: z.string().max(80).optional(),
|
|
843
|
+
}),
|
|
844
|
+
);
|
|
845
|
+
|
|
846
|
+
/** W-1020: where a media box puts its icon or image: above, or before or after the words. */
|
|
847
|
+
export const MEDIA_BOX_POSITIONS = ["top", "left", "right"] as const;
|
|
848
|
+
|
|
849
|
+
/** W-1020 / W-1021: what an icon box and an image box share: title, text, link, layout. */
|
|
850
|
+
const MediaBoxText = {
|
|
851
|
+
title: z.string().max(200),
|
|
852
|
+
/** The title's heading level. Unset = 3. */
|
|
853
|
+
titleLevel: z.number().int().min(2).max(6).optional(),
|
|
854
|
+
text: z.string().max(MAX_TEXT_LENGTH),
|
|
855
|
+
position: z.enum(MEDIA_BOX_POSITIONS).optional(),
|
|
856
|
+
/** Optional link: the title is the link, and the whole box is clickable. */
|
|
857
|
+
href: z.string().max(2000).optional(),
|
|
858
|
+
newTab: z.boolean().optional(),
|
|
859
|
+
};
|
|
860
|
+
|
|
861
|
+
/**
|
|
862
|
+
* W-1020: an icon above (or beside) a title and text, like Elementor's Icon Box. The icon is
|
|
863
|
+
* decorative: the title says what the box is. `iconId` and `iconSvg` work as on an Icon.
|
|
864
|
+
*/
|
|
865
|
+
export const IconBoxNode = leafNode(
|
|
866
|
+
"icon-box",
|
|
867
|
+
z.strictObject({
|
|
868
|
+
iconId: z.string().min(1).max(64),
|
|
869
|
+
iconSvg: z.string().max(ICON_SVG_MAX).optional(),
|
|
870
|
+
/** The icon's width and height in px. Unset = 48. */
|
|
871
|
+
iconSize: z.number().int().min(8).max(512).optional(),
|
|
872
|
+
...MediaBoxText,
|
|
873
|
+
}),
|
|
874
|
+
);
|
|
875
|
+
|
|
876
|
+
/** W-1021: how much of the box's width an image box's picture takes when beside the words. */
|
|
877
|
+
export const IMAGE_BOX_SIZES = ["small", "medium", "large", "full"] as const;
|
|
878
|
+
|
|
879
|
+
/**
|
|
880
|
+
* W-1021: a picture above (or beside) a title and text, like Elementor's Image Box. The picture
|
|
881
|
+
* keys are an Image's, so the media library fills them the same way; alt text is required unless
|
|
882
|
+
* the picture is decorative.
|
|
883
|
+
*/
|
|
884
|
+
export const ImageBoxNode = leafNode(
|
|
885
|
+
"image-box",
|
|
886
|
+
z.strictObject({
|
|
887
|
+
src: z.string().max(2000),
|
|
888
|
+
alt: z.string().max(500),
|
|
889
|
+
decorative: z.boolean().optional(),
|
|
890
|
+
mediaId: z.string().min(1).max(128).optional(),
|
|
891
|
+
width: z.number().int().positive().max(10000).optional(),
|
|
892
|
+
height: z.number().int().positive().max(10000).optional(),
|
|
893
|
+
focalX: z.number().int().min(0).max(100).optional(),
|
|
894
|
+
focalY: z.number().int().min(0).max(100).optional(),
|
|
895
|
+
/** Beside the words: small 25 %, medium 40 %, large 60 % of the box. Unset = medium. */
|
|
896
|
+
imageSize: z.enum(IMAGE_BOX_SIZES).optional(),
|
|
897
|
+
...MediaBoxText,
|
|
898
|
+
}),
|
|
899
|
+
).refine((node) => node.props.decorative === true || node.props.alt.length > 0, {
|
|
900
|
+
message: "Alt text is required unless the image is marked decorative.",
|
|
901
|
+
path: ["props", "alt"],
|
|
902
|
+
});
|
|
903
|
+
|
|
904
|
+
/**
|
|
905
|
+
* W-1022: a quote in a figure: the words as a blockquote, then who said them (name and role) with
|
|
906
|
+
* an optional photo, and an optional star rating read as "Rated 5 out of 5". The photo is shown
|
|
907
|
+
* beside the name, so it is decorative; its keys are an Image's so the media library fills them.
|
|
908
|
+
*/
|
|
909
|
+
export const TestimonialNode = leafNode(
|
|
910
|
+
"testimonial",
|
|
911
|
+
z.strictObject({
|
|
912
|
+
quote: z.string().max(MAX_TEXT_LENGTH),
|
|
913
|
+
name: z.string().max(200),
|
|
914
|
+
role: z.string().max(200).optional(),
|
|
915
|
+
src: z.string().max(2000).optional(),
|
|
916
|
+
/** Written by the media library; never rendered (the photo is beside the name). */
|
|
917
|
+
alt: z.string().max(500).optional(),
|
|
918
|
+
mediaId: z.string().min(1).max(128).optional(),
|
|
919
|
+
width: z.number().int().positive().max(10000).optional(),
|
|
920
|
+
height: z.number().int().positive().max(10000).optional(),
|
|
921
|
+
focalX: z.number().int().min(0).max(100).optional(),
|
|
922
|
+
focalY: z.number().int().min(0).max(100).optional(),
|
|
923
|
+
/** Stars out of `ratingMax` (unset 5); no stars when unset. */
|
|
924
|
+
rating: z.number().min(0).max(MAX_RATING).optional(),
|
|
925
|
+
ratingMax: z.number().int().min(1).max(MAX_RATING).optional(),
|
|
926
|
+
}),
|
|
927
|
+
);
|
|
928
|
+
|
|
929
|
+
/** W-1024: the Social icons presets (Font Awesome Free brand icons, plus email, RSS, website). */
|
|
930
|
+
export const SOCIAL_NETWORKS = [
|
|
931
|
+
"facebook",
|
|
932
|
+
"instagram",
|
|
933
|
+
"x",
|
|
934
|
+
"linkedin",
|
|
935
|
+
"youtube",
|
|
936
|
+
"tiktok",
|
|
937
|
+
"bluesky",
|
|
938
|
+
"mastodon",
|
|
939
|
+
"threads",
|
|
940
|
+
"github",
|
|
941
|
+
"pinterest",
|
|
942
|
+
"whatsapp",
|
|
943
|
+
"discord",
|
|
944
|
+
"twitch",
|
|
945
|
+
"reddit",
|
|
946
|
+
"dribbble",
|
|
947
|
+
"behance",
|
|
948
|
+
"telegram",
|
|
949
|
+
"spotify",
|
|
950
|
+
"email",
|
|
951
|
+
"rss",
|
|
952
|
+
"website",
|
|
953
|
+
] as const;
|
|
954
|
+
/** W-1024: how each icon is drawn: on its own, or in a circle, rounded or square badge. */
|
|
955
|
+
export const SOCIAL_SHAPES = ["plain", "circle", "rounded", "square"] as const;
|
|
956
|
+
|
|
957
|
+
/**
|
|
958
|
+
* W-1024: a list of links to the site's social profiles, each a brand icon named for screen
|
|
959
|
+
* readers ("Instagram"). Holds Social links only. `label` names the list (unset "Social media");
|
|
960
|
+
* `brandColors` paints each icon in its network's colour; icons follow the font size.
|
|
961
|
+
*/
|
|
962
|
+
export const SocialIconsNodeSchema = parentNode(
|
|
963
|
+
"social-icons",
|
|
964
|
+
z.strictObject({
|
|
965
|
+
label: z.string().max(80).optional(),
|
|
966
|
+
shape: z.enum(SOCIAL_SHAPES).optional(),
|
|
967
|
+
brandColors: z.boolean().optional(),
|
|
968
|
+
}),
|
|
969
|
+
);
|
|
970
|
+
|
|
971
|
+
/** W-1024: one profile link in Social icons. `label` replaces the network's name. */
|
|
972
|
+
export const SocialLinkNode = leafNode(
|
|
973
|
+
"social-link",
|
|
974
|
+
z.strictObject({
|
|
975
|
+
network: z.enum(SOCIAL_NETWORKS),
|
|
976
|
+
href: z.string().max(2000),
|
|
977
|
+
label: z.string().max(80).optional(),
|
|
978
|
+
newTab: z.boolean().optional(),
|
|
979
|
+
}),
|
|
980
|
+
);
|
|
981
|
+
|
|
982
|
+
/** W-1019: a Gallery's layout: equal squares in a grid, or each picture its own height. */
|
|
983
|
+
export const GALLERY_LAYOUTS = ["grid", "masonry"] as const;
|
|
984
|
+
|
|
985
|
+
/**
|
|
986
|
+
* W-1019: pictures from the media library in a grid or masonry columns (1–6 on wide screens; at
|
|
987
|
+
* most 2 on tablets and 1 on phones). Holds Gallery images only. `lightbox` opts in to a script
|
|
988
|
+
* that opens each picture large in a native dialog; without it the gallery uses no script.
|
|
989
|
+
*/
|
|
990
|
+
export const GalleryNodeSchema = parentNode(
|
|
991
|
+
"gallery",
|
|
992
|
+
z.strictObject({
|
|
993
|
+
layout: z.enum(GALLERY_LAYOUTS).optional(),
|
|
994
|
+
columns: z.number().int().min(1).max(6).optional(),
|
|
995
|
+
lightbox: z.boolean().optional(),
|
|
996
|
+
/** Names the list for screen readers. Unset = no name. */
|
|
997
|
+
label: z.string().max(80).optional(),
|
|
998
|
+
}),
|
|
999
|
+
);
|
|
1000
|
+
|
|
1001
|
+
/** W-1019: one picture in a Gallery: an Image's picture keys, alt text and an optional caption. */
|
|
1002
|
+
export const GalleryImageNode = leafNode(
|
|
1003
|
+
"gallery-image",
|
|
1004
|
+
z.strictObject({
|
|
1005
|
+
src: z.string().max(2000),
|
|
1006
|
+
alt: z.string().max(500),
|
|
1007
|
+
decorative: z.boolean().optional(),
|
|
1008
|
+
mediaId: z.string().min(1).max(128).optional(),
|
|
1009
|
+
width: z.number().int().positive().max(10000).optional(),
|
|
1010
|
+
height: z.number().int().positive().max(10000).optional(),
|
|
1011
|
+
focalX: z.number().int().min(0).max(100).optional(),
|
|
1012
|
+
focalY: z.number().int().min(0).max(100).optional(),
|
|
1013
|
+
caption: z.string().max(500).optional(),
|
|
1014
|
+
}),
|
|
1015
|
+
).refine((node) => node.props.decorative === true || node.props.alt.length > 0, {
|
|
1016
|
+
message: "Alt text is required unless the picture is marked decorative.",
|
|
1017
|
+
path: ["props", "alt"],
|
|
1018
|
+
});
|
|
1019
|
+
|
|
1020
|
+
/**
|
|
1021
|
+
* W-1018: slides on a horizontal track that snaps to each one, swiped, scrolled or moved with
|
|
1022
|
+
* the arrow keys, with no script. `arrows`, `dots` and `autoplay` opt in to the carousel
|
|
1023
|
+
* script, which adds those controls. Autoplay is off unless set; when on, a visible Pause button
|
|
1024
|
+
* comes first, hovering or focusing the carousel pauses it, and under reduced motion it starts
|
|
1025
|
+
* paused (WCAG 2.2.2). `perView` slides show at once (at most 2 on tablets, 1 on phones).
|
|
1026
|
+
*/
|
|
1027
|
+
export const CarouselNodeSchema = parentNode(
|
|
1028
|
+
"carousel",
|
|
1029
|
+
z.strictObject({
|
|
1030
|
+
/** Names the carousel for screen readers. Unset = "Carousel". */
|
|
1031
|
+
label: z.string().max(80).optional(),
|
|
1032
|
+
perView: z.number().int().min(1).max(4).optional(),
|
|
1033
|
+
arrows: z.boolean().optional(),
|
|
1034
|
+
dots: z.boolean().optional(),
|
|
1035
|
+
autoplay: z.boolean().optional(),
|
|
1036
|
+
/** Seconds per slide while playing. Unset = 6. */
|
|
1037
|
+
interval: z.number().int().min(3).max(30).optional(),
|
|
1038
|
+
/** After the last slide, Next and autoplay go back to the first. */
|
|
1039
|
+
loop: z.boolean().optional(),
|
|
1040
|
+
}),
|
|
1041
|
+
);
|
|
1042
|
+
|
|
1043
|
+
/** W-1018: one slide; holds any elements. `label` names it instead of "2 of 5". */
|
|
1044
|
+
export const CarouselSlideNode = parentNode(
|
|
1045
|
+
"carousel-slide",
|
|
1046
|
+
z.strictObject({
|
|
1047
|
+
label: z.string().max(80).optional(),
|
|
1048
|
+
}),
|
|
1049
|
+
);
|
|
1050
|
+
|
|
794
1051
|
const knownTypeSet = new Set<string>(KNOWN_ELEMENT_TYPES);
|
|
795
1052
|
|
|
796
1053
|
/**
|
|
@@ -808,7 +1065,7 @@ const UnknownNodeSchema = z.strictObject({
|
|
|
808
1065
|
props: z.record(z.string(), z.unknown()),
|
|
809
1066
|
...sharedNodeFields,
|
|
810
1067
|
get children(): z.ZodType<LayoutNode[] | undefined> {
|
|
811
|
-
return
|
|
1068
|
+
return ChildList.optional();
|
|
812
1069
|
},
|
|
813
1070
|
});
|
|
814
1071
|
|
|
@@ -824,6 +1081,17 @@ const KnownLayoutNode = z.discriminatedUnion("type", [
|
|
|
824
1081
|
HeadingNode,
|
|
825
1082
|
TocNode,
|
|
826
1083
|
LanguageSwitcherNode,
|
|
1084
|
+
RatingNode,
|
|
1085
|
+
AlertNode,
|
|
1086
|
+
IconBoxNode,
|
|
1087
|
+
ImageBoxNode,
|
|
1088
|
+
TestimonialNode,
|
|
1089
|
+
SocialIconsNodeSchema,
|
|
1090
|
+
SocialLinkNode,
|
|
1091
|
+
GalleryNodeSchema,
|
|
1092
|
+
GalleryImageNode,
|
|
1093
|
+
CarouselNodeSchema,
|
|
1094
|
+
CarouselSlideNode,
|
|
827
1095
|
SpacerNode,
|
|
828
1096
|
DividerNode,
|
|
829
1097
|
TextNode,
|
|
@@ -864,6 +1132,13 @@ export const KNOWN_NODE_SCHEMAS = KnownLayoutNode.options;
|
|
|
864
1132
|
export type HeadingNode = z.infer<typeof HeadingNode>;
|
|
865
1133
|
export type TocNode = z.infer<typeof TocNode>;
|
|
866
1134
|
export type LanguageSwitcherNode = z.infer<typeof LanguageSwitcherNode>;
|
|
1135
|
+
export type RatingNode = z.infer<typeof RatingNode>;
|
|
1136
|
+
export type AlertNode = z.infer<typeof AlertNode>;
|
|
1137
|
+
export type IconBoxNode = z.infer<typeof IconBoxNode>;
|
|
1138
|
+
export type ImageBoxNode = z.infer<typeof ImageBoxNode>;
|
|
1139
|
+
export type TestimonialNode = z.infer<typeof TestimonialNode>;
|
|
1140
|
+
export type SocialLinkNode = z.infer<typeof SocialLinkNode>;
|
|
1141
|
+
export type GalleryImageNode = z.infer<typeof GalleryImageNode>;
|
|
867
1142
|
export type SpacerNode = z.infer<typeof SpacerNode>;
|
|
868
1143
|
export type DividerNode = z.infer<typeof DividerNode>;
|
|
869
1144
|
export type TextNode = z.infer<typeof TextNode>;
|
|
@@ -1029,6 +1304,30 @@ export type AccordionNode = NodeEnvelope & {
|
|
|
1029
1304
|
children: LayoutNode[];
|
|
1030
1305
|
};
|
|
1031
1306
|
|
|
1307
|
+
export type SocialIconsNode = NodeEnvelope & {
|
|
1308
|
+
type: "social-icons";
|
|
1309
|
+
props: z.infer<typeof SocialIconsNodeSchema>["props"];
|
|
1310
|
+
children: LayoutNode[];
|
|
1311
|
+
};
|
|
1312
|
+
|
|
1313
|
+
export type CarouselNode = NodeEnvelope & {
|
|
1314
|
+
type: "carousel";
|
|
1315
|
+
props: z.infer<typeof CarouselNodeSchema>["props"];
|
|
1316
|
+
children: LayoutNode[];
|
|
1317
|
+
};
|
|
1318
|
+
|
|
1319
|
+
export type CarouselSlideNode = NodeEnvelope & {
|
|
1320
|
+
type: "carousel-slide";
|
|
1321
|
+
props: { label?: string };
|
|
1322
|
+
children: LayoutNode[];
|
|
1323
|
+
};
|
|
1324
|
+
|
|
1325
|
+
export type GalleryNode = NodeEnvelope & {
|
|
1326
|
+
type: "gallery";
|
|
1327
|
+
props: z.infer<typeof GalleryNodeSchema>["props"];
|
|
1328
|
+
children: LayoutNode[];
|
|
1329
|
+
};
|
|
1330
|
+
|
|
1032
1331
|
export type MenuNode = NodeEnvelope & {
|
|
1033
1332
|
type: "menu";
|
|
1034
1333
|
props: { direction: "row" | "column"; label?: string };
|
|
@@ -1063,6 +1362,17 @@ export type LayoutNode =
|
|
|
1063
1362
|
| HeadingNode
|
|
1064
1363
|
| TocNode
|
|
1065
1364
|
| LanguageSwitcherNode
|
|
1365
|
+
| RatingNode
|
|
1366
|
+
| AlertNode
|
|
1367
|
+
| IconBoxNode
|
|
1368
|
+
| ImageBoxNode
|
|
1369
|
+
| TestimonialNode
|
|
1370
|
+
| SocialIconsNode
|
|
1371
|
+
| SocialLinkNode
|
|
1372
|
+
| GalleryNode
|
|
1373
|
+
| GalleryImageNode
|
|
1374
|
+
| CarouselNode
|
|
1375
|
+
| CarouselSlideNode
|
|
1066
1376
|
| SpacerNode
|
|
1067
1377
|
| DividerNode
|
|
1068
1378
|
| TextNode
|
|
@@ -1093,6 +1403,9 @@ export type LayoutNode =
|
|
|
1093
1403
|
| MenuItemNode
|
|
1094
1404
|
| UnknownNode;
|
|
1095
1405
|
|
|
1406
|
+
/** S-03: the issues one element reports before "…and N more". */
|
|
1407
|
+
const MAX_NODE_ISSUES = 10;
|
|
1408
|
+
|
|
1096
1409
|
/**
|
|
1097
1410
|
* Prefer the known-type schema when `type` is registered so path-specific Zod issues stay
|
|
1098
1411
|
* intact; only fall through to UnknownNode for types EmVB does not implement (W-022 / R-033).
|
|
@@ -1114,7 +1427,8 @@ const LayoutNode: z.ZodType<LayoutNode> = z.lazy(() =>
|
|
|
1114
1427
|
? KnownLayoutNode.safeParse(input)
|
|
1115
1428
|
: UnknownNodeSchema.safeParse(input);
|
|
1116
1429
|
if (!result.success) {
|
|
1117
|
-
|
|
1430
|
+
const issues = result.error.issues;
|
|
1431
|
+
for (const issue of issues.slice(0, MAX_NODE_ISSUES)) {
|
|
1118
1432
|
ctx.addIssue({
|
|
1119
1433
|
code: "custom",
|
|
1120
1434
|
path: issue.path,
|
|
@@ -1122,12 +1436,68 @@ const LayoutNode: z.ZodType<LayoutNode> = z.lazy(() =>
|
|
|
1122
1436
|
params: { zodCode: issue.code },
|
|
1123
1437
|
});
|
|
1124
1438
|
}
|
|
1439
|
+
// S-03: a node re-emits a few issues, not one per bad item, so a parent's count stays small.
|
|
1440
|
+
if (issues.length > MAX_NODE_ISSUES) {
|
|
1441
|
+
ctx.addIssue({
|
|
1442
|
+
code: "custom",
|
|
1443
|
+
path: [],
|
|
1444
|
+
message: `…and ${issues.length - MAX_NODE_ISSUES} more problems in this element.`,
|
|
1445
|
+
params: { zodCode: "too_many_issues" },
|
|
1446
|
+
});
|
|
1447
|
+
}
|
|
1125
1448
|
return z.NEVER;
|
|
1126
1449
|
}
|
|
1127
1450
|
return result.data as LayoutNode;
|
|
1128
1451
|
}),
|
|
1129
1452
|
);
|
|
1130
1453
|
|
|
1454
|
+
/** S-03: the issues a list of children reports before the rest of them is skipped. */
|
|
1455
|
+
const MAX_CHILD_ISSUES = 40;
|
|
1456
|
+
|
|
1457
|
+
/**
|
|
1458
|
+
* Children parse one at a time and stop once they have reported MAX_CHILD_ISSUES issues: a
|
|
1459
|
+
* page of a thousand bad elements cost one issue list per element (180 MB on a 512 KB page).
|
|
1460
|
+
*/
|
|
1461
|
+
const ChildList: z.ZodType<LayoutNode[]> = z.lazy(() =>
|
|
1462
|
+
z.array(z.unknown()).transform((items, ctx) => {
|
|
1463
|
+
const nodes: LayoutNode[] = [];
|
|
1464
|
+
let reported = 0;
|
|
1465
|
+
for (const [index, item] of items.entries()) {
|
|
1466
|
+
if (reported >= MAX_CHILD_ISSUES) {
|
|
1467
|
+
ctx.addIssue({
|
|
1468
|
+
code: "custom",
|
|
1469
|
+
path: [index],
|
|
1470
|
+
message: "…and more problems in the elements after this one.",
|
|
1471
|
+
params: { zodCode: "too_many_issues" },
|
|
1472
|
+
});
|
|
1473
|
+
return z.NEVER;
|
|
1474
|
+
}
|
|
1475
|
+
const result = LayoutNode.safeParse(item);
|
|
1476
|
+
if (result.success) {
|
|
1477
|
+
nodes.push(result.data);
|
|
1478
|
+
continue;
|
|
1479
|
+
}
|
|
1480
|
+
for (const issue of result.error.issues) {
|
|
1481
|
+
const params =
|
|
1482
|
+
"params" in issue ? (issue.params as { zodCode?: unknown } | undefined) : undefined;
|
|
1483
|
+
ctx.addIssue({
|
|
1484
|
+
code: "custom",
|
|
1485
|
+
path: [index, ...issue.path],
|
|
1486
|
+
message: issue.message,
|
|
1487
|
+
params: {
|
|
1488
|
+
zodCode:
|
|
1489
|
+
issue.code === "custom" && typeof params?.zodCode === "string"
|
|
1490
|
+
? params.zodCode
|
|
1491
|
+
: issue.code,
|
|
1492
|
+
},
|
|
1493
|
+
});
|
|
1494
|
+
reported++;
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
return reported > 0 ? z.NEVER : nodes;
|
|
1498
|
+
}),
|
|
1499
|
+
);
|
|
1500
|
+
|
|
1131
1501
|
export const Layout = z.strictObject({
|
|
1132
1502
|
schemaVersion: z.literal(LAYOUT_SCHEMA_VERSION),
|
|
1133
1503
|
root: ContainerNode,
|
|
@@ -1181,7 +1551,8 @@ export const isLayoutParentNode = (
|
|
|
1181
1551
|
| SectionNode
|
|
1182
1552
|
| LoopEmptyNode
|
|
1183
1553
|
| AccordionItemNode
|
|
1184
|
-
| MenuItemNode
|
|
1554
|
+
| MenuItemNode
|
|
1555
|
+
| CarouselSlideNode =>
|
|
1185
1556
|
node.type === "container" ||
|
|
1186
1557
|
node.type === "div-block" ||
|
|
1187
1558
|
node.type === "layout-section" ||
|
|
@@ -1191,7 +1562,8 @@ export const isLayoutParentNode = (
|
|
|
1191
1562
|
node.type === "part-ref" ||
|
|
1192
1563
|
node.type === "loop-empty" ||
|
|
1193
1564
|
node.type === "accordion-item" ||
|
|
1194
|
-
node.type === "menu-item"
|
|
1565
|
+
node.type === "menu-item" ||
|
|
1566
|
+
node.type === "carousel-slide";
|
|
1195
1567
|
|
|
1196
1568
|
/** Nodes that may hold children. */
|
|
1197
1569
|
export const isParentNode = (
|
|
@@ -1211,7 +1583,11 @@ export const isParentNode = (
|
|
|
1211
1583
|
| AccordionNode
|
|
1212
1584
|
| AccordionItemNode
|
|
1213
1585
|
| MenuNode
|
|
1214
|
-
| MenuItemNode
|
|
1586
|
+
| MenuItemNode
|
|
1587
|
+
| SocialIconsNode
|
|
1588
|
+
| GalleryNode
|
|
1589
|
+
| CarouselNode
|
|
1590
|
+
| CarouselSlideNode =>
|
|
1215
1591
|
node.type === "container" ||
|
|
1216
1592
|
node.type === "div-block" ||
|
|
1217
1593
|
node.type === "layout-section" ||
|
|
@@ -1226,7 +1602,11 @@ export const isParentNode = (
|
|
|
1226
1602
|
node.type === "accordion" ||
|
|
1227
1603
|
node.type === "accordion-item" ||
|
|
1228
1604
|
node.type === "menu" ||
|
|
1229
|
-
node.type === "menu-item"
|
|
1605
|
+
node.type === "menu-item" ||
|
|
1606
|
+
node.type === "social-icons" ||
|
|
1607
|
+
node.type === "gallery" ||
|
|
1608
|
+
node.type === "carousel" ||
|
|
1609
|
+
node.type === "carousel-slide";
|
|
1230
1610
|
|
|
1231
1611
|
export const isFormFieldType = (type: string): boolean =>
|
|
1232
1612
|
(FORM_FIELD_TYPES as readonly string[]).includes(type);
|
package/src/core/schema/style.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { boundedArray } from "../bounded-array.ts";
|
|
1
2
|
import { z } from "zod";
|
|
2
3
|
import {
|
|
3
4
|
ALIGN_ITEMS,
|
|
@@ -552,6 +553,6 @@ export const DeviceStyles = z.strictObject({
|
|
|
552
553
|
export type DeviceStyles = z.infer<typeof DeviceStyles>;
|
|
553
554
|
|
|
554
555
|
/** Devices on which the element is `display: none`. Empty means shown everywhere. */
|
|
555
|
-
export const HiddenOn =
|
|
556
|
+
export const HiddenOn = boundedArray(z.enum(DEVICES), 4);
|
|
556
557
|
|
|
557
558
|
export type HiddenOn = z.infer<typeof HiddenOn>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* S-12 (W-1001): element ids that would replace a browser global a host script reads (DOM
|
|
3
|
+
* clobbering: `<div id="location">` makes `window.location` checks in old scripts see the
|
|
4
|
+
* element). The renderer leaves such an id out and the editor refuses it; stored layouts keep
|
|
5
|
+
* it, so no page saved by an older EmVB is refused. `top` stays allowed: `#top` links are common.
|
|
6
|
+
*/
|
|
7
|
+
const SHADOWING = new Set([
|
|
8
|
+
"anchors",
|
|
9
|
+
"body",
|
|
10
|
+
"closed",
|
|
11
|
+
"cookie",
|
|
12
|
+
"defaultView",
|
|
13
|
+
"document",
|
|
14
|
+
"documentElement",
|
|
15
|
+
"domain",
|
|
16
|
+
"embeds",
|
|
17
|
+
"forms",
|
|
18
|
+
"frameElement",
|
|
19
|
+
"frames",
|
|
20
|
+
"globalThis",
|
|
21
|
+
"head",
|
|
22
|
+
"history",
|
|
23
|
+
"images",
|
|
24
|
+
"length",
|
|
25
|
+
"links",
|
|
26
|
+
"localStorage",
|
|
27
|
+
"location",
|
|
28
|
+
"name",
|
|
29
|
+
"navigator",
|
|
30
|
+
"opener",
|
|
31
|
+
"origin",
|
|
32
|
+
"parent",
|
|
33
|
+
"plugins",
|
|
34
|
+
"scripts",
|
|
35
|
+
"self",
|
|
36
|
+
"sessionStorage",
|
|
37
|
+
"status",
|
|
38
|
+
"window",
|
|
39
|
+
]);
|
|
40
|
+
|
|
41
|
+
export const isShadowingId = (id: string): boolean => SHADOWING.has(id);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { boundedArray } from "../bounded-array.ts";
|
|
1
2
|
import { z } from "zod";
|
|
2
3
|
import { parseDoc } from "./parse-doc.ts";
|
|
3
4
|
import { type ContentThemePartType, type ThemePartType } from "./part-types.ts";
|
|
@@ -17,7 +18,7 @@ const ConditionRuleSchema = z.strictObject({
|
|
|
17
18
|
|
|
18
19
|
const ConditionsDocSchema = z.strictObject({
|
|
19
20
|
schemaVersion: z.literal(CONDITIONS_SCHEMA_VERSION),
|
|
20
|
-
rules:
|
|
21
|
+
rules: boundedArray(ConditionRuleSchema, MAX_CONDITION_RULES),
|
|
21
22
|
});
|
|
22
23
|
|
|
23
24
|
export type ConditionRule = z.infer<typeof ConditionRuleSchema>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { capIssues } from "../issue-cap.ts";
|
|
1
2
|
import type { z } from "zod";
|
|
2
3
|
|
|
3
4
|
export type DocIssue = { path: string; code: string; message: string };
|
|
@@ -27,10 +28,14 @@ export function parseDoc<T>(
|
|
|
27
28
|
if (parsed.success) return { ok: true, doc: parsed.data };
|
|
28
29
|
return {
|
|
29
30
|
ok: false,
|
|
30
|
-
issues:
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
issues: capIssues(
|
|
32
|
+
parsed.error.issues,
|
|
33
|
+
(issue) => ({
|
|
34
|
+
path: issue.path.length ? `${root}.${issue.path.join(".")}` : root,
|
|
35
|
+
code: issue.code,
|
|
36
|
+
message: issue.message,
|
|
37
|
+
}),
|
|
38
|
+
root,
|
|
39
|
+
),
|
|
35
40
|
};
|
|
36
41
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { boundedArray } from "../bounded-array.ts";
|
|
1
2
|
import { z } from "zod";
|
|
2
3
|
import { parseDoc } from "./parse-doc.ts";
|
|
3
4
|
import { POPUP_DEVICES, TRIGGER_LIMITS } from "./popup-rules.ts";
|
|
@@ -46,14 +47,14 @@ const DeviceSchema = z.enum(POPUP_DEVICES);
|
|
|
46
47
|
*/
|
|
47
48
|
const AdvancedRulesSchema = z.strictObject({
|
|
48
49
|
showTimes: z.number().int().min(1).max(MAX_SHOW_TIMES).nullable().optional(),
|
|
49
|
-
devices:
|
|
50
|
+
devices: boundedArray(DeviceSchema, 3).nullable().optional(),
|
|
50
51
|
});
|
|
51
52
|
|
|
52
53
|
export type PopupAdvancedRules = z.infer<typeof AdvancedRulesSchema>;
|
|
53
54
|
|
|
54
55
|
const TriggersDocSchema = z.strictObject({
|
|
55
56
|
schemaVersion: z.literal(TRIGGERS_SCHEMA_VERSION),
|
|
56
|
-
open:
|
|
57
|
+
open: boundedArray(PopupOpenTriggerSchema, MAX_POPUP_TRIGGERS, 1),
|
|
57
58
|
advanced: AdvancedRulesSchema.default({}),
|
|
58
59
|
});
|
|
59
60
|
|