@claspo/templates 16.0.3 → 16.0.4

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.
@@ -3,7 +3,6 @@ export default class TemplateMapper {
3
3
  static mapTemplates(rawItems: TemplateBriefI[]): TemplateBriefI[];
4
4
  private static migrateCssVarsToTheme;
5
5
  private static applyThemeToDocument;
6
- private static enableThemeRelatedFlagForCloseIconIfItUsingTheme;
7
6
  private static applyInlineBackgroundToDocument;
8
7
  private static cleanupTemplateIfItWasChangedFromDynamicToStatic;
9
8
  }
package/TemplateMapper.js CHANGED
@@ -1 +1 @@
1
- import{TemplateType}from"./TemplateType.enum";import DocumentCssVarsReplace from"@claspo/common/document/DocumentCssVarsReplace";import DocumentUtils from"@claspo/common/document/DocumentUtils";import{DefaultSchemaTokens}from"@claspo/common/document/Document.interface";import{prepareKeys}from"@claspo/common/element/ThemeCssVars";import{createTheme,formCssVarToSchemaToken,THEME_CSS_VAR_PREFIX,toCssVarToken}from"@claspo/common/theme/theme.utils";export default class TemplateMapper{static mapTemplates(e){return e.map(e=>{var o;if(e.type===TemplateType.STATIC)return TemplateMapper.cleanupTemplateIfItWasChangedFromDynamicToStatic(e),e;const a=TemplateMapper.migrateCssVarsToTheme(e);a&&TemplateMapper.applyThemeToDocument(e,a);const t=null===(o=e.dynamicParams)||void 0===o?void 0:o.backgroundInline;return t&&TemplateMapper.applyInlineBackgroundToDocument(e,t),e})}static migrateCssVarsToTheme(e){var o,a;const t=null===(o=e.dynamicParams)||void 0===o?void 0:o.cssVars;let m=null===(a=e.dynamicParams)||void 0===a?void 0:a.theme;if(!m&&t){const e=t[toCssVarToken(DefaultSchemaTokens.ACCENT)];e&&(m=createTheme({[DefaultSchemaTokens.ACCENT]:e}))}return m||null}static applyThemeToDocument(e,o){const a=e.json.document,t=prepareKeys((null==o?void 0:o.schema)||{});e.json.document=DocumentCssVarsReplace.replaceValues(a,t),e.json.document.shared||(e.json.document.shared={}),TemplateMapper.enableThemeRelatedFlagForCloseIconIfItUsingTheme(e.json.document,"desktop"),TemplateMapper.enableThemeRelatedFlagForCloseIconIfItUsingTheme(e.json.document,"mobile"),e.json.document.shared.theme=o}static enableThemeRelatedFlagForCloseIconIfItUsingTheme(e,o){var a,t;const m=null===(a=e.shared.closeIcon)||void 0===a?void 0:a[o];(null===(t=null==m?void 0:m.color)||void 0===t?void 0:t.includes(`var(--${THEME_CSS_VAR_PREFIX}`))&&(m.colorThemeToken=formCssVarToSchemaToken(m.color))}static applyInlineBackgroundToDocument(e,o){null==o||o.forEach(({path:o,props:a})=>{const t=DocumentUtils.getNodeByPath(e.json.document.views,o);t&&(t.props=Object.assign(Object.assign({},t.props),a))})}static cleanupTemplateIfItWasChangedFromDynamicToStatic(e){if(e.dynamicParams){delete e.dynamicParams.theme,delete e.dynamicParams.cssVars;const o=e.json.document;(null==o?void 0:o.shared)&&(delete o.shared.theme,delete o.shared.cssVars)}}}
1
+ import{TemplateType}from"./TemplateType.enum";import DocumentCssVarsReplace from"@claspo/common/document/DocumentCssVarsReplace";import DocumentUtils from"@claspo/common/document/DocumentUtils";import{DefaultSchemaTokens}from"@claspo/common/document/Document.interface";import{prepareKeys}from"@claspo/common/element/ThemeCssVars";import{createTheme,toCssVarToken}from"@claspo/common/theme/theme.utils";export default class TemplateMapper{static mapTemplates(e){return e.map(e=>{var a;if(e.type===TemplateType.STATIC)return TemplateMapper.cleanupTemplateIfItWasChangedFromDynamicToStatic(e),e;const t=TemplateMapper.migrateCssVarsToTheme(e);t&&TemplateMapper.applyThemeToDocument(e,t);const o=null===(a=e.dynamicParams)||void 0===a?void 0:a.backgroundInline;return o&&TemplateMapper.applyInlineBackgroundToDocument(e,o),e})}static migrateCssVarsToTheme(e){var a,t;const o=null===(a=e.dynamicParams)||void 0===a?void 0:a.cssVars;let m=null===(t=e.dynamicParams)||void 0===t?void 0:t.theme;if(!m&&o){const e=o[toCssVarToken(DefaultSchemaTokens.ACCENT)];e&&(m=createTheme({[DefaultSchemaTokens.ACCENT]:e}))}return m||null}static applyThemeToDocument(e,a){const t=e.json.document,o=prepareKeys((null==a?void 0:a.schema)||{});e.json.document=DocumentCssVarsReplace.replaceValues(t,o),e.json.document.shared||(e.json.document.shared={}),e.json.document.shared.theme=a}static applyInlineBackgroundToDocument(e,a){null==a||a.forEach(({path:a,props:t})=>{const o=DocumentUtils.getNodeByPath(e.json.document.views,a);o&&(o.props=Object.assign(Object.assign({},o.props),t))})}static cleanupTemplateIfItWasChangedFromDynamicToStatic(e){if(e.dynamicParams){delete e.dynamicParams.theme,delete e.dynamicParams.cssVars;const a=e.json.document;(null==a?void 0:a.shared)&&(delete a.shared.theme,delete a.shared.cssVars)}}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@claspo/templates",
3
- "version": "16.0.3",
3
+ "version": "16.0.4",
4
4
  "engines": {
5
5
  "node": ">=18.16.0"
6
6
  },
@@ -12,9 +12,9 @@
12
12
  "package": "npm i && npm run test && npm run build && cp package.json out && cd out && npm publish --access=public && cd .."
13
13
  },
14
14
  "dependencies": {
15
- "@claspo/common": "7.0.1",
16
- "@claspo/document-connector": "16.0.1",
17
- "@claspo/renderer": "18.0.1",
15
+ "@claspo/common": "7.0.2",
16
+ "@claspo/document-connector": "16.0.3",
17
+ "@claspo/renderer": "18.0.2",
18
18
  "@claspo/components": "1.2.0"
19
19
  },
20
20
  "devDependencies": {