@the-smithy/hearth-schema 0.22.0 → 0.24.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/dist/index.d.ts CHANGED
@@ -311,6 +311,22 @@ declare const customBlockDefinitionSchema: z.ZodObject<{
311
311
  }, z.core.$strip>]>>;
312
312
  }, z.core.$strip>;
313
313
  type CustomBlockDefinition = z.infer<typeof customBlockDefinitionSchema>;
314
+ /**
315
+ * A global block's key, set when it's created and fixed after: menus, pop-up links and frontends refer to it
316
+ * ("contact", "newsletter"). Global blocks are edited once and shown anywhere: on pages (a `sharedBlock` block), as
317
+ * a pop-up, or in a menu dropdown.
318
+ */
319
+ declare const globalBlockKey: RegExp;
320
+ /** A global block shown as a pop-up: links to `#popup-<key>` open it, and `button` adds a floating button that does. */
321
+ declare const globalPopupSchema: z.ZodObject<{
322
+ title: z.ZodOptional<z.ZodString>;
323
+ button: z.ZodOptional<z.ZodString>;
324
+ }, z.core.$strip>;
325
+ type GlobalPopup = z.infer<typeof globalPopupSchema>;
326
+ /** The link that opens a global block's pop-up: "#popup-contact". */
327
+ declare const popupHref: (key: string) => string;
328
+ /** The global block key a pop-up link opens ("#popup-contact" → "contact"), or null for any other link. */
329
+ declare function popupKey(href: string): string | null;
314
330
  /** Validates a custom block's `values` against its definition (the block schema itself can't: it's per site). */
315
331
  declare function customValuesSchema(fields: CustomField[]): z.ZodType<Record<string, unknown>>;
316
332
  declare const blockDataSchemas: {
@@ -724,6 +740,7 @@ declare const blockDataSchemas: {
724
740
  tag: z.ZodOptional<z.ZodString>;
725
741
  categoryId: z.ZodOptional<z.ZodString>;
726
742
  }, z.core.$strip>;
743
+ /** One of the site's global blocks, by id. The API inlines it (and adds `shared`); frontends never see this type. */
727
744
  readonly sharedBlock: z.ZodObject<{
728
745
  sharedBlockId: z.ZodString;
729
746
  }, z.core.$strip>;
@@ -2537,6 +2554,7 @@ declare const siteSettingsSchema: z.ZodObject<{
2537
2554
  navigation: z.ZodDefault<z.ZodArray<z.ZodObject<{
2538
2555
  label: z.ZodString;
2539
2556
  href: z.ZodString;
2557
+ dropdown: z.ZodOptional<z.ZodString>;
2540
2558
  }, z.core.$strip>>>;
2541
2559
  navigationCta: z.ZodOptional<z.ZodObject<{
2542
2560
  label: z.ZodString;
@@ -3061,7 +3079,7 @@ type HearthForm = {
3061
3079
  submitLabel: string;
3062
3080
  successMessage: string;
3063
3081
  };
3064
- /** Blocks as the API returns them: event blocks carry their events, shared blocks say where they came from. */
3082
+ /** Blocks as the API returns them: event blocks carry their events, global blocks say where they came from. */
3065
3083
  type Resolved<T extends BlockType> = T extends "hero" ? {
3066
3084
  id: string;
3067
3085
  type: T;
@@ -3134,12 +3152,15 @@ type Resolved<T extends BlockType> = T extends "hero" ? {
3134
3152
  type: T;
3135
3153
  data: BlockData<T>;
3136
3154
  };
3155
+ /** On a block that came from one of the site's global blocks: which one (`key` from Hearth versions with global blocks). */
3156
+ type SharedFrom = {
3157
+ id: string;
3158
+ name: string;
3159
+ key?: string;
3160
+ };
3137
3161
  type KnownBlock = {
3138
3162
  [T in Exclude<BlockType, "sharedBlock">]: Resolved<T> & {
3139
- shared?: {
3140
- id: string;
3141
- name: string;
3142
- };
3163
+ shared?: SharedFrom;
3143
3164
  };
3144
3165
  }[Exclude<BlockType, "sharedBlock">];
3145
3166
  /** A block type added to the library after this package version: render it if you can, skip it if not. */
@@ -3147,16 +3168,38 @@ type UnknownBlock = {
3147
3168
  id: string;
3148
3169
  type: string & {};
3149
3170
  data: unknown;
3150
- shared?: {
3151
- id: string;
3152
- name: string;
3153
- };
3171
+ shared?: SharedFrom;
3154
3172
  };
3155
3173
  type ResolvedBlock = KnownBlock | UnknownBlock;
3156
3174
  /** One block type, narrowed: BlockOf<"hero">. */
3157
3175
  type BlockOf<T extends Exclude<BlockType, "sharedBlock">> = Extract<KnownBlock, {
3158
3176
  type: T;
3159
3177
  }>;
3178
+ /**
3179
+ * One of the site's global blocks (GET /global-blocks, or one by key or id at GET /global-blocks/{key or id}): edited
3180
+ * once in Hearth and shown anywhere. Place any of them wherever the site needs one; Hearth's own placements say where
3181
+ * editors put it: `popup` (render it in a dialog that links to `#popup-<key>` open, with a floating button when
3182
+ * `popup.button` is set) and `usedOn.menuItems` (main menu items whose `dropdown` names it).
3183
+ */
3184
+ type GlobalBlock = {
3185
+ id: string;
3186
+ /** Fixed once made: refer to it by this in code. */
3187
+ key: string;
3188
+ name: string;
3189
+ /** The block's type ("form", "cta"…), as on `block.type`. */
3190
+ type: string;
3191
+ /** For a `custom` block, the site's custom block it is (its key); otherwise null. */
3192
+ customBlock: string | null;
3193
+ popup: GlobalPopup | null;
3194
+ /** Where editors placed it: the live pages it's on (paths) and the main menu items it drops down from (labels). */
3195
+ usedOn: {
3196
+ pages: string[];
3197
+ menuItems: string[];
3198
+ };
3199
+ publishedAt: string | null;
3200
+ updatedAt: string;
3201
+ block: ResolvedBlock;
3202
+ };
3160
3203
  /** Where a site's tracker sends page views (<HearthAnalytics /> from `@the-smithy/hearth/analytics`). */
3161
3204
  type SiteAnalytics = {
3162
3205
  /** The collector's address. */
@@ -3252,4 +3295,4 @@ type ApiErrorBody = {
3252
3295
  };
3253
3296
  };
3254
3297
 
3255
- export { type AnalyticsReport, type AnalyticsRow, type ApiErrorBody, BLOCK_SCHEMA_VERSION, type Block, type BlockData, type BlockOf, type BlockType, COLLECTION_SCHEMA_TYPES, type CategoryGroup, type CategoryRef, type Collection, type CollectionEntry, type CollectionRef, type CollectionSchemaType, type CustomBlockDefinition, type CustomField, type CustomFieldKind, DAYS_OF_WEEK, type DonationCheckout, type DonationInput, EMBED_ALLOW, EMBED_SANDBOX, type EntryDetails, type EventCustomFields, type EventRegistration, type EventTicket, type EventVolunteerShift, type EventVolunteering, type FormDefinition, type FormField, type Fundraiser, type FundraiserDetail, type HearthEvent, type HearthEventDetail, type HearthForm, type ImageRef, type KnownBlock, LODGING_TYPES, type LinkRef, ORGANIZATION_TYPES, type OrganizationType, PLACE_TYPES, type Page, type PageContent, type PageMeta, type PageSummary, type Position, type Redirect, type RegistrationInput, type RegistrationResult, type ResolvedBlock, SITE_LOCALES, SOCIAL_PLATFORMS, type Seo, type Site, type SiteAnalytics, type SiteSettings, type SitemapEntry, type TicketType, type UnknownBlock, VOLUNTEER_RESERVED_KEYS, type VolunteerForm, type VolunteerInput, type VolunteerResult, type VolunteerShift, type WebhookPayload, blockDataSchemas, blockFeature, blockSchema, blockTypes, customBlockDefinitionSchema, customBlockKey, customFieldSchema, customValuesSchema, directionsUrl, embedDocument, focalPosition, formDefinitionSchema, formFieldSchema, pageContentSchema, parseBlocks, parsePageContent, parseSiteSettings, parseTicketTypes, parseVolunteerForm, parseVolunteerShifts, pinned, seoSchema, siteSettingsSchema, ticketTypeSchema, ticketTypesSchema, videoEmbedUrl, volunteerFormSchema, volunteerShiftSchema, volunteerShiftsSchema };
3298
+ export { type AnalyticsReport, type AnalyticsRow, type ApiErrorBody, BLOCK_SCHEMA_VERSION, type Block, type BlockData, type BlockOf, type BlockType, COLLECTION_SCHEMA_TYPES, type CategoryGroup, type CategoryRef, type Collection, type CollectionEntry, type CollectionRef, type CollectionSchemaType, type CustomBlockDefinition, type CustomField, type CustomFieldKind, DAYS_OF_WEEK, type DonationCheckout, type DonationInput, EMBED_ALLOW, EMBED_SANDBOX, type EntryDetails, type EventCustomFields, type EventRegistration, type EventTicket, type EventVolunteerShift, type EventVolunteering, type FormDefinition, type FormField, type Fundraiser, type FundraiserDetail, type GlobalBlock, type GlobalPopup, type HearthEvent, type HearthEventDetail, type HearthForm, type ImageRef, type KnownBlock, LODGING_TYPES, type LinkRef, ORGANIZATION_TYPES, type OrganizationType, PLACE_TYPES, type Page, type PageContent, type PageMeta, type PageSummary, type Position, type Redirect, type RegistrationInput, type RegistrationResult, type ResolvedBlock, SITE_LOCALES, SOCIAL_PLATFORMS, type Seo, type SharedFrom, type Site, type SiteAnalytics, type SiteSettings, type SitemapEntry, type TicketType, type UnknownBlock, VOLUNTEER_RESERVED_KEYS, type VolunteerForm, type VolunteerInput, type VolunteerResult, type VolunteerShift, type WebhookPayload, blockDataSchemas, blockFeature, blockSchema, blockTypes, customBlockDefinitionSchema, customBlockKey, customFieldSchema, customValuesSchema, directionsUrl, embedDocument, focalPosition, formDefinitionSchema, formFieldSchema, globalBlockKey, globalPopupSchema, pageContentSchema, parseBlocks, parsePageContent, parseSiteSettings, parseTicketTypes, parseVolunteerForm, parseVolunteerShifts, pinned, popupHref, popupKey, seoSchema, siteSettingsSchema, ticketTypeSchema, ticketTypesSchema, videoEmbedUrl, volunteerFormSchema, volunteerShiftSchema, volunteerShiftsSchema };
package/dist/index.js CHANGED
@@ -72,6 +72,18 @@ var customBlockDefinitionSchema = z.object({
72
72
  description: z.string().trim().max(200).default(""),
73
73
  fields: z.array(customFieldSchema).min(1, "Add at least one field.").max(30).refine(uniqueNames, "Two fields share a name.").refine((fs) => fs.every((f) => f.kind !== "list" || uniqueNames(f.fields)), "Two fields in a list share a name.")
74
74
  });
75
+ var globalBlockKey = customBlockKey;
76
+ var globalPopupSchema = z.object({
77
+ /** The pop-up's heading; without one, its name is read out to screen readers. */
78
+ title: z.string().trim().max(80).optional(),
79
+ /** Text of a button fixed to the corner of every page that opens the pop-up, e.g. "Contact us". */
80
+ button: z.string().trim().max(40).optional()
81
+ });
82
+ var popupHref = (key) => `#popup-${key}`;
83
+ function popupKey(href) {
84
+ const m = /^#popup-([a-z][a-z0-9]*(?:-[a-z0-9]+)*)$/.exec(href.trim());
85
+ return m ? m[1] : null;
86
+ }
75
87
  function customValuesSchema(fields) {
76
88
  const one = (f) => {
77
89
  const required = !f.optional;
@@ -375,8 +387,9 @@ var blockDataSchemas = {
375
387
  /** Only entries in this category (e.g. "Featured"). */
376
388
  categoryId: z.string().uuid().optional()
377
389
  }),
390
+ /** One of the site's global blocks, by id. The API inlines it (and adds `shared`); frontends never see this type. */
378
391
  sharedBlock: z.object({
379
- sharedBlockId: z.string().uuid("Choose a shared block")
392
+ sharedBlockId: z.string().uuid("Choose a global block")
380
393
  }),
381
394
  /** One fundraiser with its progress (giving feature). The API adds `fundraiser`. */
382
395
  fundraiserSpotlight: z.object({
@@ -638,8 +651,9 @@ var time = z2.string().regex(/^([01]\d|2[0-3]):[0-5]\d$/, "Use 24-hour time like
638
651
  var link2 = z2.object({ label: z2.string().trim().min(1, "Add link text."), href: z2.string().trim().min(1, "Add where it goes.") });
639
652
  var SITE_LOCALES = ["en_US", "en_GB", "en_CA", "en_AU", "es_US", "es_ES", "es_MX", "fr_CA", "fr_FR", "de_DE", "pt_BR"];
640
653
  var SOCIAL_PLATFORMS = ["facebook", "instagram", "linkedin", "x", "youtube", "tiktok", "other"];
654
+ var navItem = link2.extend({ dropdown: z2.string().regex(globalBlockKey).optional() });
641
655
  var siteSettingsSchema = z2.object({
642
- navigation: z2.array(link2).default([]),
656
+ navigation: z2.array(navItem).default([]),
643
657
  /** An optional button at the end of the main menu, e.g. "Book now" or "Donate". Frontends style it as a button. */
644
658
  navigationCta: link2.optional(),
645
659
  footerLinks: z2.array(link2).default([]),
@@ -852,6 +866,8 @@ export {
852
866
  focalPosition,
853
867
  formDefinitionSchema,
854
868
  formFieldSchema,
869
+ globalBlockKey,
870
+ globalPopupSchema,
855
871
  pageContentSchema,
856
872
  parseBlocks,
857
873
  parsePageContent,
@@ -860,6 +876,8 @@ export {
860
876
  parseVolunteerForm,
861
877
  parseVolunteerShifts,
862
878
  pinned,
879
+ popupHref,
880
+ popupKey,
863
881
  seoSchema,
864
882
  siteSettingsSchema,
865
883
  ticketTypeSchema,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@the-smithy/hearth-schema",
3
- "version": "0.22.0",
3
+ "version": "0.24.0",
4
4
  "description": "Content schemas and API types shared by Hearth and its SDK.",
5
5
  "type": "module",
6
6
  "license": "SEE LICENSE IN LICENSE",