@templatical/template-tools 0.38.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"src-unNYVMlC.js","names":["rawSchema"],"sources":["../schema.json","../src/validate.ts","../src/operations.ts"],"sourcesContent":["","// Structural validation of a Templatical template against the generated JSON\n// Schema, plus the @templatical/quality lint layered on top.\n//\n// Structural validation is discriminator-aware: each block is checked against\n// the subschema for its declared `type` (e.g. a block with `\"type\": \"button\"`\n// is validated as a ButtonBlock), so errors are precise (\"blocks[2] (button)\n// must have required property 'url'\") instead of the raw anyOf's \"must match\n// exactly one schema in anyOf\".\n\nimport Ajv, { type ValidateFunction, type ErrorObject } from \"ajv\";\nimport { lintTemplate, type LintIssue } from \"@templatical/quality\";\nimport type { TemplateContent } from \"@templatical/types\";\nimport rawSchema from \"../schema.json\";\n\ninterface SchemaDefinition {\n properties?: { type?: { const?: unknown } } & Record<string, unknown>;\n [key: string]: unknown;\n}\n\ninterface SchemaDocument {\n definitions: Record<string, SchemaDefinition>;\n [key: string]: unknown;\n}\n\n/** The generated JSON Schema for `TemplateContent`, as a plain object. */\nexport const schema = rawSchema as unknown as SchemaDocument;\n\nconst ajv = new Ajv({ allErrors: true, strict: false });\n\n// Map a block's `type` discriminator (e.g. \"button\", \"social\") to its schema\n// definition name (e.g. \"ButtonBlock\", \"SocialIconsBlock\"), derived from the\n// schema itself so it never drifts from the generated defs.\nconst typeToDef: Record<string, string> = {};\nfor (const [name, def] of Object.entries(schema.definitions)) {\n const constType = def?.properties?.type?.const;\n if (typeof constType === \"string\") {\n typeToDef[constType] = name;\n }\n}\n\nconst validatorCache = new Map<string, ValidateFunction>();\n\nfunction validatorFor(defName: string): ValidateFunction {\n const cached = validatorCache.get(defName);\n if (cached) return cached;\n\n const definitions = structuredClone(schema.definitions);\n // A section's `children` holds nested blocks (Block[][]); we recurse into\n // them separately for precise paths, so stub the deep check here.\n if (defName === \"SectionBlock\") {\n const section = definitions.SectionBlock;\n if (section?.properties) {\n section.properties.children = { type: \"array\" };\n }\n }\n const compiled = ajv.compile({\n $ref: `#/definitions/${defName}`,\n definitions,\n });\n validatorCache.set(defName, compiled);\n return compiled;\n}\n\nconst settingsValidator = ajv.compile({\n $ref: \"#/definitions/TemplateSettings\",\n definitions: structuredClone(schema.definitions),\n});\n\ninterface FlatBlock {\n path: string;\n block: Record<string, unknown> | null;\n}\n\nfunction flattenBlocks(\n blocks: unknown,\n basePath: string,\n out: FlatBlock[],\n): void {\n if (!Array.isArray(blocks)) return;\n blocks.forEach((block, i) => {\n const path = `${basePath}[${i}]`;\n out.push({ path, block: block ?? null });\n if (block?.type === \"section\" && Array.isArray(block.children)) {\n block.children.forEach((column: unknown, ci: number) => {\n flattenBlocks(column, `${path}.children[${ci}]`, out);\n });\n }\n });\n}\n\nfunction formatAjvErrors(\n errors: ErrorObject[] | null | undefined,\n prefix: string,\n): string[] {\n return (errors ?? []).map((e) => {\n const where = `${prefix}${e.instancePath}`;\n const extra =\n e.keyword === \"additionalProperties\"\n ? ` (${(e.params as { additionalProperty?: string }).additionalProperty})`\n : \"\";\n return `${where} ${e.message}${extra}`;\n });\n}\n\nexport interface ValidationResult {\n valid: boolean;\n errors: string[];\n}\n\n/**\n * Structural validation. Synchronous, depends only on ajv + the committed\n * schema.json (no build of the workspace packages required).\n */\nexport function validateTemplate(data: unknown): ValidationResult {\n const errors: string[] = [];\n\n if (data === null || typeof data !== \"object\" || Array.isArray(data)) {\n return { valid: false, errors: [\"(root) must be an object\"] };\n }\n\n const doc = data as Record<string, unknown>;\n\n if (!Array.isArray(doc.blocks)) {\n errors.push(\"blocks must be an array\");\n }\n if (doc.settings === null || typeof doc.settings !== \"object\") {\n errors.push(\"settings must be an object\");\n } else if (!settingsValidator(doc.settings)) {\n errors.push(...formatAjvErrors(settingsValidator.errors, \"settings\"));\n }\n\n const flat: FlatBlock[] = [];\n flattenBlocks(doc.blocks, \"blocks\", flat);\n for (const { path, block } of flat) {\n const type = block?.type;\n const defName = typeof type === \"string\" ? typeToDef[type] : undefined;\n if (!defName) {\n const known = Object.keys(typeToDef).join(\", \");\n errors.push(\n `${path} has unknown or missing block type ${JSON.stringify(type)} (expected one of: ${known})`,\n );\n continue;\n }\n const validate = validatorFor(defName);\n if (!validate(block)) {\n errors.push(...formatAjvErrors(validate.errors, `${path} (${type})`));\n }\n }\n\n return { valid: errors.length === 0, errors };\n}\n\nexport interface QualityLintResult {\n issues: LintIssue[];\n /** Set when the linter itself threw — the template is structurally suspect. */\n error?: string;\n}\n\n/**\n * Quality layer — accessibility / structure / link linting.\n *\n * Assumes structurally-valid input, so callers should run `validateTemplate`\n * first; the try/catch is a guard against a malformed template crashing the\n * linter rather than a substitute for that ordering.\n */\nexport function runQualityLint(data: unknown): QualityLintResult {\n try {\n return { issues: lintTemplate(data as TemplateContent) ?? [] };\n } catch (err) {\n return { issues: [], error: (err as Error).message };\n }\n}\n","// A pure reducer over the template operation vocabulary.\n//\n// `applyOperation(content, payload) -> { ok, content, error }`. The input is\n// never mutated: every operation works on a `safeClone` and returns a new\n// document, so a rejected operation leaves the caller's copy provably untouched.\n//\n// Two deliberate differences from the editor's own mutators in\n// `@templatical/core` (`src/editor.ts`), which this mirrors:\n//\n// 1. **Failure is explicit.** Core silently `return`s on an invalid operation,\n// which is right for a UI — a drag that can't drop simply doesn't. An agent\n// gets no such feedback, so a silent no-op would read as success and the\n// next instruction would build on a state that never happened. Every\n// rejection here carries a reason.\n// 2. **No collaboration locks.** `lockedBlocks` is a Cloud concern; this runs\n// against a local working file with a single writer.\n//\n// Core is FSL and cannot be imported here, so the shared invariants — above all\n// the section-into-column refusal (issue #292) — are reimplemented. That is a\n// real drift risk: a guard added to core will not appear here. `tests/\n// operations.test.ts` states each invariant against both descriptions so the\n// pair has to be reconciled deliberately.\n//\n// Note the payload keys are camelCase (`blockId`, `targetSectionId`), matching\n// `@templatical/types` and core. Cloud's MCP tools emit snake_case in their own\n// `data` payloads, so this reducer is NOT wire-compatible with Cloud broadcasts\n// and is not meant to be.\n\nimport { safeClone } from \"@templatical/types\";\nimport type {\n Block,\n ColumnLayout,\n TemplateOperationPayload,\n SectionBlock,\n TemplateContent,\n TemplateSettings,\n} from \"@templatical/types\";\n\n/** Columns a layout declares. Mirrors the helper in core's editor. */\nexport function getColumnCount(layout: ColumnLayout): number {\n if (layout === \"1\") return 1;\n if (layout === \"3\") return 3;\n return 2;\n}\n\nfunction findBlockById(blocks: Block[], id: string): Block | null {\n for (const block of blocks) {\n if (block.id === id) return block;\n if (block.type === \"section\") {\n for (const column of block.children) {\n const found = findBlockById(column, id);\n if (found) return found;\n }\n }\n }\n return null;\n}\n\ninterface ParentRef {\n blocks: Block[];\n sectionId?: string;\n columnIndex?: number;\n}\n\nfunction findBlockParent(\n blocks: Block[],\n id: string,\n parent: ParentRef = { blocks },\n): ParentRef | null {\n for (const block of blocks) {\n if (block.id === id) return parent;\n if (block.type === \"section\") {\n for (let colIdx = 0; colIdx < block.children.length; colIdx++) {\n const result = findBlockParent(block.children[colIdx], id, {\n blocks: block.children[colIdx],\n sectionId: block.id,\n columnIndex: colIdx,\n });\n if (result) return result;\n }\n }\n }\n return null;\n}\n\nexport interface OperationResult {\n ok: boolean;\n /** The new document on success; the unchanged input on failure. */\n content: TemplateContent;\n error?: string;\n}\n\nfunction reject(content: TemplateContent, error: string): OperationResult {\n return { ok: false, content, error };\n}\n\n/**\n * Resolve the array an operation targets, enforcing the column rules.\n * Returns a string on rejection so callers can surface the reason.\n */\nfunction resolveTarget(\n content: TemplateContent,\n targetSectionId: string | undefined,\n columnIndex: number,\n): Block[] | string {\n if (!targetSectionId) return content.blocks;\n\n const section = findBlockById(content.blocks, targetSectionId);\n if (!section) return `No block with id \"${targetSectionId}\".`;\n if (section.type !== \"section\") {\n return `Block \"${targetSectionId}\" is a ${section.type}, not a section — it has no columns.`;\n }\n const count = getColumnCount((section as SectionBlock).columns);\n if (columnIndex < 0 || columnIndex >= count) {\n return `Column ${columnIndex} is out of range for a \"${(section as SectionBlock).columns}\" section (${count} column(s)).`;\n }\n const children = section as SectionBlock;\n children.children[columnIndex] = children.children[columnIndex] || [];\n return children.children[columnIndex];\n}\n\nfunction insertAt(target: Block[], block: Block, index?: number): void {\n if (index !== undefined && index < target.length) {\n target.splice(index, 0, block);\n } else {\n target.push(block);\n }\n}\n\ntype Data = Record<string, unknown>;\n\n/** Apply one operation, returning a new document. Never mutates the input. */\nexport function applyOperation(\n content: TemplateContent,\n payload: TemplateOperationPayload,\n): OperationResult {\n const data = (payload.data ?? {}) as Data;\n\n switch (payload.operation) {\n case \"setContent\": {\n const next = data.content as TemplateContent | undefined;\n if (!next || typeof next !== \"object\" || !Array.isArray(next.blocks)) {\n return reject(\n content,\n \"setContent needs `content` with a blocks array.\",\n );\n }\n return { ok: true, content: safeClone(next) };\n }\n\n case \"updateSettings\": {\n const updates = data.settings as Partial<TemplateSettings> | undefined;\n if (!updates || typeof updates !== \"object\") {\n return reject(content, \"updateSettings needs a `settings` object.\");\n }\n const draft = safeClone(content);\n draft.settings = { ...draft.settings, ...updates };\n return { ok: true, content: draft };\n }\n\n case \"addBlock\": {\n const block = data.block as Block | undefined;\n if (!block || typeof block !== \"object\" || typeof block.id !== \"string\") {\n return reject(content, \"addBlock needs a `block` with an id.\");\n }\n const targetSectionId = data.targetSectionId as string | undefined;\n\n // Sections cannot nest inside a column — MJML forbids `mj-section` inside\n // `mj-column`, so the renderer drops them on export (issue #292). Reject\n // up front rather than lose the content silently at render time.\n if (targetSectionId && block.type === \"section\") {\n return reject(\n content,\n \"A section cannot be nested inside a section column — MJML would drop it on export. Add it at the top level instead.\",\n );\n }\n\n const draft = safeClone(content);\n if (findBlockById(draft.blocks, block.id)) {\n return reject(content, `A block with id \"${block.id}\" already exists.`);\n }\n const target = resolveTarget(\n draft,\n targetSectionId,\n (data.columnIndex as number | undefined) ?? 0,\n );\n if (typeof target === \"string\") return reject(content, target);\n\n insertAt(target, safeClone(block), data.index as number | undefined);\n return { ok: true, content: draft };\n }\n\n case \"updateBlock\": {\n const blockId = data.blockId as string | undefined;\n const updates = data.updates as Partial<Block> | undefined;\n if (!blockId) return reject(content, \"updateBlock needs a `blockId`.\");\n if (!updates || typeof updates !== \"object\") {\n return reject(content, \"updateBlock needs an `updates` object.\");\n }\n const draft = safeClone(content);\n const block = findBlockById(draft.blocks, blockId);\n if (!block) return reject(content, `No block with id \"${blockId}\".`);\n if (\"type\" in updates && updates.type !== block.type) {\n // Changing type in place would leave the block carrying the previous\n // type's fields, which no longer validate against its new subschema.\n return reject(\n content,\n `Cannot change a block's type (${block.type} → ${String(updates.type)}). Delete it and add the new block instead.`,\n );\n }\n Object.assign(block, updates);\n return { ok: true, content: draft };\n }\n\n case \"updateBlockStyle\": {\n const blockId = data.blockId as string | undefined;\n const styles = data.styles as Record<string, unknown> | undefined;\n if (!blockId) {\n return reject(content, \"updateBlockStyle needs a `blockId`.\");\n }\n if (!styles || typeof styles !== \"object\") {\n return reject(content, \"updateBlockStyle needs a `styles` object.\");\n }\n const draft = safeClone(content);\n const block = findBlockById(draft.blocks, blockId);\n if (!block) return reject(content, `No block with id \"${blockId}\".`);\n // Merge rather than replace, so a caller can set one property without\n // restating padding and every other style the block already carries.\n block.styles = {\n ...block.styles,\n ...styles,\n } as Block[\"styles\"];\n return { ok: true, content: draft };\n }\n\n case \"deleteBlock\": {\n const blockId = data.blockId as string | undefined;\n if (!blockId) return reject(content, \"deleteBlock needs a `blockId`.\");\n const draft = safeClone(content);\n const parent = findBlockParent(draft.blocks, blockId);\n if (!parent) return reject(content, `No block with id \"${blockId}\".`);\n const index = parent.blocks.findIndex((b) => b.id === blockId);\n parent.blocks.splice(index, 1);\n return { ok: true, content: draft };\n }\n\n case \"moveBlock\": {\n const blockId = data.blockId as string | undefined;\n const index = data.index as number | undefined;\n if (!blockId) return reject(content, \"moveBlock needs a `blockId`.\");\n if (typeof index !== \"number\" || index < 0) {\n return reject(content, \"moveBlock needs a non-negative `index`.\");\n }\n const targetSectionId = data.targetSectionId as string | undefined;\n\n const draft = safeClone(content);\n const parent = findBlockParent(draft.blocks, blockId);\n if (!parent) return reject(content, `No block with id \"${blockId}\".`);\n const oldIndex = parent.blocks.findIndex((b) => b.id === blockId);\n\n if (targetSectionId && parent.blocks[oldIndex].type === \"section\") {\n return reject(\n content,\n \"A section cannot be moved into a section column — MJML would drop it on export.\",\n );\n }\n if (targetSectionId === blockId) {\n return reject(content, \"A block cannot be moved into itself.\");\n }\n\n // Resolve the target BEFORE splicing the source: an invalid target would\n // otherwise leave the block removed and unrecoverable.\n const target = resolveTarget(\n draft,\n targetSectionId,\n (data.columnIndex as number | undefined) ?? 0,\n );\n if (typeof target === \"string\") return reject(content, target);\n\n const [block] = parent.blocks.splice(oldIndex, 1);\n target.splice(index, 0, block);\n return { ok: true, content: draft };\n }\n\n default: {\n return reject(\n content,\n `Unknown operation \"${String(payload.operation)}\".`,\n );\n }\n }\n}\n"],"mappings":";;;;;;ACyBA,MAAa,SAASA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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