@templatical/template-tools 0.45.0 → 0.47.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-Ce1Oh8m_.js","names":[],"sources":["../src/operations.ts"],"sourcesContent":["// 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":";;;;AAuCA,SAAgB,eAAe,QAA8B;CAC3D,IAAI,WAAW,KAAK,OAAO;CAC3B,IAAI,WAAW,KAAK,OAAO;CAC3B,OAAO;AACT;AAEA,SAAS,cAAc,QAAiB,IAA0B;CAChE,KAAK,MAAM,SAAS,QAAQ;EAC1B,IAAI,MAAM,OAAO,IAAI,OAAO;EAC5B,IAAI,MAAM,SAAS,WACjB,KAAK,MAAM,UAAU,MAAM,UAAU;GACnC,MAAM,QAAQ,cAAc,QAAQ,EAAE;GACtC,IAAI,OAAO,OAAO;EACpB;CAEJ;CACA,OAAO;AACT;AAQA,SAAS,gBACP,QACA,IACA,SAAoB,EAAE,OAAO,GACX;CAClB,KAAK,MAAM,SAAS,QAAQ;EAC1B,IAAI,MAAM,OAAO,IAAI,OAAO;EAC5B,IAAI,MAAM,SAAS,WACjB,KAAK,IAAI,SAAS,GAAG,SAAS,MAAM,SAAS,QAAQ,UAAU;GAC7D,MAAM,SAAS,gBAAgB,MAAM,SAAS,SAAS,IAAI;IACzD,QAAQ,MAAM,SAAS;IACvB,WAAW,MAAM;IACjB,aAAa;GACf,CAAC;GACD,IAAI,QAAQ,OAAO;EACrB;CAEJ;CACA,OAAO;AACT;AASA,SAAS,OAAO,SAA0B,OAAgC;CACxE,OAAO;EAAE,IAAI;EAAO;EAAS;CAAM;AACrC;;;;;AAMA,SAAS,cACP,SACA,iBACA,aACkB;CAClB,IAAI,CAAC,iBAAiB,OAAO,QAAQ;CAErC,MAAM,UAAU,cAAc,QAAQ,QAAQ,eAAe;CAC7D,IAAI,CAAC,SAAS,OAAO,qBAAqB,gBAAgB;CAC1D,IAAI,QAAQ,SAAS,WACnB,OA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ACL,SACA,sBAAsB,OAAO,QAAQ,SAAS,EAAE,GAClD;CAEJ;AACF"}
package/live/index.html CHANGED
@@ -1304,6 +1304,58 @@
1304
1304
  };
1305
1305
 
1306
1306
  // ---- Boot ----
1307
+ // ---- Custom-block mode ----
1308
+ // The bridge serves the definition without its preview recipe; onFetch
1309
+ // asks the bridge, which holds the recipe and the secrets. The page sends
1310
+ // fieldValues only — never a URL or headers.
1311
+ let customBlock = null; // { definition, dataSource: { label } | null }
1312
+
1313
+ async function loadCustomBlock() {
1314
+ try {
1315
+ const res = await fetch("/custom-block");
1316
+ if (res.status === 200) {
1317
+ customBlock = await res.json();
1318
+ } else {
1319
+ customBlock = null;
1320
+ if (res.status === 422) {
1321
+ toast((await res.json().catch(() => ({}))).error ?? "Custom block is invalid");
1322
+ }
1323
+ }
1324
+ } catch {
1325
+ customBlock = null;
1326
+ }
1327
+ }
1328
+
1329
+ function customBlocksConfig() {
1330
+ if (!customBlock) return undefined;
1331
+ const definition = { ...customBlock.definition };
1332
+ if (customBlock.dataSource) {
1333
+ definition.dataSource = {
1334
+ label: customBlock.dataSource.label,
1335
+ onFetch: async ({ fieldValues }) => {
1336
+ const res = await fetch("/data-source/fetch", {
1337
+ method: "POST",
1338
+ headers: { "content-type": "application/json" },
1339
+ body: JSON.stringify({ fieldValues }),
1340
+ });
1341
+ const body = await res.json().catch(() => ({}));
1342
+ // Throwing (not returning null, which reads as "cancelled") puts
1343
+ // the toolbar in its fetch-error state, which stays visible.
1344
+ if (!res.ok) {
1345
+ const message = body.error ?? "Fetch failed";
1346
+ toast(message);
1347
+ throw new Error(message);
1348
+ }
1349
+ if (body.unmapped?.length) {
1350
+ toast("Not in the response: " + body.unmapped.join(", "));
1351
+ }
1352
+ return body.values;
1353
+ },
1354
+ };
1355
+ }
1356
+ return [definition];
1357
+ }
1358
+
1307
1359
  async function mountEditor(content) {
1308
1360
  applyingRemote = true;
1309
1361
  try {
@@ -1316,6 +1368,7 @@
1316
1368
  locale: readLocale(),
1317
1369
  content, // undefined → editor starts from its default empty template
1318
1370
  uiTheme: readTheme(),
1371
+ customBlocks: customBlocksConfig(),
1319
1372
  onChange: () => {
1320
1373
  if (!applyingRemote) scheduleContentPost();
1321
1374
  },
@@ -1328,6 +1381,7 @@
1328
1381
  }
1329
1382
 
1330
1383
  async function boot() {
1384
+ await loadCustomBlock();
1331
1385
  let content;
1332
1386
  try {
1333
1387
  const res = await fetch("/template");
@@ -1348,6 +1402,16 @@
1348
1402
  /* malformed frame; ignore */
1349
1403
  }
1350
1404
  });
1405
+ es.addEventListener("custom-block", async (e) => {
1406
+ try {
1407
+ const { block, template } = JSON.parse(e.data);
1408
+ customBlock = block;
1409
+ await mountEditor(template);
1410
+ toast("Updated from agent");
1411
+ } catch {
1412
+ /* malformed frame; ignore */
1413
+ }
1414
+ });
1351
1415
  es.onopen = () => setStatus("live", "Live");
1352
1416
  es.onerror = () => setStatus("reconnecting", "Reconnecting…");
1353
1417
  }
package/package.json CHANGED
@@ -1,23 +1,25 @@
1
1
  {
2
2
  "name": "@templatical/template-tools",
3
3
  "description": "CLI and library for Templatical email templates — validate, render, edit, import, and live-preview",
4
- "version": "0.45.0",
4
+ "version": "0.47.0",
5
5
  "bin": {
6
6
  "templatical": "./dist/bin.js"
7
7
  },
8
8
  "bugs": "https://github.com/templatical/sdk/issues",
9
9
  "dependencies": {
10
- "@templatical/quality": "0.45.0",
11
- "@templatical/renderer": "0.45.0",
12
- "@templatical/types": "0.45.0",
13
- "ajv": "^8.20.0"
10
+ "@templatical/quality": "0.47.0",
11
+ "@templatical/renderer": "0.47.0",
12
+ "@templatical/types": "0.47.0",
13
+ "ajv": "^8.20.0",
14
+ "htmlparser2": "^12.0.0",
15
+ "liquidjs": "^10.30.0"
14
16
  },
15
17
  "devDependencies": {
16
18
  "@types/node": "^25.9.9",
17
19
  "mjml": "^5.4.1",
18
20
  "ts-json-schema-generator": "^2.9.0",
19
21
  "typescript": "^6.0.3",
20
- "vitest": "^5.0.3"
22
+ "vitest": "^5.0.4"
21
23
  },
22
24
  "exports": {
23
25
  ".": {
@@ -28,13 +30,15 @@
28
30
  "types": "./dist/live/index.d.ts",
29
31
  "import": "./dist/live/index.js"
30
32
  },
31
- "./schema.json": "./schema.json"
33
+ "./schema.json": "./schema.json",
34
+ "./custom-block-schema.json": "./custom-block-schema.json"
32
35
  },
33
36
  "files": [
34
37
  "README.md",
35
38
  "dist",
36
39
  "live",
37
- "schema.json"
40
+ "schema.json",
41
+ "custom-block-schema.json"
38
42
  ],
39
43
  "homepage": "https://templatical.com",
40
44
  "keywords": [
@@ -48,14 +52,14 @@
48
52
  "license": "MIT",
49
53
  "module": "./dist/index.js",
50
54
  "peerDependencies": {
51
- "@templatical/import-beefree": "0.45.0",
52
- "@templatical/import-chamaileon": "0.45.0",
53
- "@templatical/import-easy-email-pro": "0.45.0",
54
- "@templatical/import-html": "0.45.0",
55
- "@templatical/import-mjml": "0.45.0",
56
- "@templatical/import-stripo": "0.45.0",
57
- "@templatical/import-topol": "0.45.0",
58
- "@templatical/import-unlayer": "0.45.0",
55
+ "@templatical/import-beefree": "0.47.0",
56
+ "@templatical/import-chamaileon": "0.47.0",
57
+ "@templatical/import-easy-email-pro": "0.47.0",
58
+ "@templatical/import-html": "0.47.0",
59
+ "@templatical/import-mjml": "0.47.0",
60
+ "@templatical/import-stripo": "0.47.0",
61
+ "@templatical/import-topol": "0.47.0",
62
+ "@templatical/import-unlayer": "0.47.0",
59
63
  "mjml": "^5.4.1"
60
64
  },
61
65
  "peerDependenciesMeta": {
package/schema.json CHANGED
@@ -140,6 +140,10 @@
140
140
  "$ref": "#/definitions/BorderValue",
141
141
  "description": "Border around the section box, per side. Omitted = no border; a side with width 0 is not drawn."
142
142
  },
143
+ "backgroundImage": {
144
+ "$ref": "#/definitions/BackgroundImage",
145
+ "description": "Image behind the section's columns, rendered as `background-url` (plus size, position and repeat) on the `mj-section`. `styles.backgroundColor` is its fallback."
146
+ },
143
147
  "wrapper": {
144
148
  "$ref": "#/definitions/SectionWrapper",
145
149
  "description": "Optional outer frame (rendered as an `mj-wrapper` around the section)."
@@ -310,6 +314,70 @@
310
314
  "dotted"
311
315
  ]
312
316
  },
317
+ "BackgroundImage": {
318
+ "type": "object",
319
+ "properties": {
320
+ "url": {
321
+ "type": "string"
322
+ },
323
+ "size": {
324
+ "$ref": "#/definitions/BackgroundSize"
325
+ },
326
+ "position": {
327
+ "type": "object",
328
+ "properties": {
329
+ "x": {
330
+ "$ref": "#/definitions/BackgroundPositionX"
331
+ },
332
+ "y": {
333
+ "$ref": "#/definitions/BackgroundPositionY"
334
+ }
335
+ },
336
+ "required": [
337
+ "x",
338
+ "y"
339
+ ],
340
+ "additionalProperties": false
341
+ },
342
+ "repeat": {
343
+ "type": "boolean",
344
+ "description": "`false` paints the image once; `true` tiles it."
345
+ }
346
+ },
347
+ "required": [
348
+ "url",
349
+ "size",
350
+ "position",
351
+ "repeat"
352
+ ],
353
+ "additionalProperties": false,
354
+ "description": "An image painted behind a section or a wrapper band. The element's own `backgroundColor` is its fallback: it shows while the image loads, with images off, and in clients without background-image support."
355
+ },
356
+ "BackgroundSize": {
357
+ "type": "string",
358
+ "enum": [
359
+ "cover",
360
+ "contain",
361
+ "auto"
362
+ ],
363
+ "description": "`background-size` keywords. In Outlook on Windows (VML), `cover` and `contain` draw a single frame when `repeat` is off and tile when it is on; `auto` always tiles from the top center, whatever `position` and `repeat` say."
364
+ },
365
+ "BackgroundPositionX": {
366
+ "type": "string",
367
+ "enum": [
368
+ "left",
369
+ "center",
370
+ "right"
371
+ ]
372
+ },
373
+ "BackgroundPositionY": {
374
+ "type": "string",
375
+ "enum": [
376
+ "top",
377
+ "center",
378
+ "bottom"
379
+ ]
380
+ },
313
381
  "SectionWrapper": {
314
382
  "type": "object",
315
383
  "properties": {
@@ -322,10 +390,14 @@
322
390
  "borderRadius": {
323
391
  "$ref": "#/definitions/BorderRadiusValue",
324
392
  "description": "Corner radius in px for the outer frame — one number, or a radius per corner. Omitted/0 = square corners."
393
+ },
394
+ "backgroundImage": {
395
+ "$ref": "#/definitions/BackgroundImage",
396
+ "description": "Image behind the band; `backgroundColor` is its fallback."
325
397
  }
326
398
  },
327
399
  "additionalProperties": false,
328
- "description": "Optional outer frame for a section. When present, the section is rendered inside an `mj-wrapper` — a full-width band (its own background + padding) that frames the section, e.g. a white card sitting on a colored band."
400
+ "description": "Optional outer frame for a section. When present, the section is rendered inside an `mj-wrapper` — a band (its own background + padding) that frames the section, e.g. a white card sitting on a colored band. The band is as wide as the email body (`settings.width`), not the recipient's viewport."
329
401
  },
330
402
  "TitleBlock": {
331
403
  "type": "object",
@@ -1567,6 +1639,10 @@
1567
1639
  "renderedHtml": {
1568
1640
  "type": "string"
1569
1641
  },
1642
+ "renderedStylesheet": {
1643
+ "type": "string",
1644
+ "description": "The definition's `stylesheet`, copied in when `renderedHtml` is written. A render provider's backend, and Cloud rendering from storage, have no definition to ask, so `@templatical/renderer` emits this when no `getCustomBlockStylesheet` resolver is passed. A resolver, when passed, decides every type, so a stale copy never overrides a live definition."
1645
+ },
1570
1646
  "dataSourceFetched": {
1571
1647
  "type": "boolean"
1572
1648
  }
@@ -1681,6 +1757,10 @@
1681
1757
  },
1682
1758
  "borderRadius": {
1683
1759
  "type": "number"
1760
+ },
1761
+ "backgroundImage": {
1762
+ "$ref": "#/definitions/BackgroundImage",
1763
+ "description": "Image behind the band; `styles.backgroundColor` is its fallback."
1684
1764
  }
1685
1765
  },
1686
1766
  "required": [
@@ -1690,7 +1770,7 @@
1690
1770
  "type"
1691
1771
  ],
1692
1772
  "additionalProperties": false,
1693
- "description": "Layout-only band rendered as `mj-wrapper`. The block is the band: `styles.backgroundColor` / `styles.padding` / `borderRadius` map to the wrapper. Legal in layout only this ship."
1773
+ "description": "Layout-only band rendered as `mj-wrapper`. The block is the band: `styles.backgroundColor` / `styles.padding` / `borderRadius` / `backgroundImage` map to the wrapper. Legal in layout only."
1694
1774
  },
1695
1775
  "TemplateSettings": {
1696
1776
  "type": "object",