@onderwijsin/nuxt-loops-renderer 0.3.0 → 0.4.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/README.md CHANGED
@@ -7,8 +7,8 @@ produced by `@onderwijsin/loops-core` into safe, styled Vue components that can
7
7
  archives, previews, and other presentation surfaces.
8
8
 
9
9
  The module is designed for content that has already been parsed on a trusted server. It validates
10
- the AST again at the browser boundary, resolves supported variables and URLs safely, and silently
11
- omits invalid or unsupported content.
10
+ the AST in the renderer, resolves supported variables and URLs safely, and silently omits invalid or
11
+ unsupported content.
12
12
 
13
13
  ## Getting started
14
14
 
@@ -73,11 +73,12 @@ const parsedAst = await getParsedCampaignAst();
73
73
 
74
74
  The component accepts the following props:
75
75
 
76
- | Prop | Required | Description |
77
- | ----------- | -------- | ----------------------------------------------------------------------------------- |
78
- | `data` | Yes | A `LoopsLmxAst` root returned by `@onderwijsin/loops-core`. |
79
- | `variables` | Yes | Values available to `{contact.*}`, `{event.*}`, and `{data.*}` merge tags. |
80
- | `config` | No | Per-renderer overrides for debugging, styles, color mapping, themes and evaluation. |
76
+ | Prop | Required | Description |
77
+ | ----------- | -------- | -------------------------------------------------------------------------------------- |
78
+ | `data` | Yes | A `LoopsLmxAst` root returned by `@onderwijsin/loops-core`. |
79
+ | `variables` | Yes | Values available to `{contact.*}`, `{event.*}`, and `{data.*}` merge tags. |
80
+ | `config` | No | Per-renderer overrides for debugging, styles, color mapping, themes and evaluation. |
81
+ | `server` | No | Enable static HTML rendering inside a host Nuxt server component. Defaults to `false`. |
81
82
 
82
83
  ```vue
83
84
  <LoopsRenderer :data="parsedAst" :variables="variables" :config="{ applyInlineStyles: false }" />
@@ -99,6 +100,73 @@ not rendered as raw HTML.
99
100
  <LoopsRenderer :data="parsedAst" :variables="variables" :config="{ debug: import.meta.dev }" />
100
101
  ```
101
102
 
103
+ ## Static server previews
104
+
105
+ Enable Nuxt component islands and place `<LoopsRenderer server>` inside a host `.server.vue`
106
+ component with a single root element. The preview renders during SSR and client navigation. Omit
107
+ `server` for reactive client rendering.
108
+ [Nuxt server components](https://nuxt.com/docs/4.x/guide/concepts/server-components)
109
+
110
+ ```ts
111
+ // nuxt.config.ts
112
+ export default defineNuxtConfig({
113
+ modules: ["@onderwijsin/nuxt-loops-renderer"],
114
+ experimental: { componentIslands: true },
115
+ routeRules: {
116
+ "/preview/**": {
117
+ cache: false,
118
+ prerender: false,
119
+ headers: { "Cache-Control": "private, no-store" }
120
+ },
121
+ "/__nuxt_island/**": { cache: false, prerender: false }
122
+ }
123
+ });
124
+ ```
125
+
126
+ ```vue
127
+ <!-- app/components/CampaignPreview.server.vue -->
128
+ <script setup lang="ts">
129
+ import type { LoopsLmxAst, LoopsLmxVariables } from "@onderwijsin/loops-core";
130
+
131
+ const { campaignId } = defineProps<{ campaignId: string }>();
132
+ const { ast, variables } = await useRequestFetch()<{
133
+ ast: LoopsLmxAst;
134
+ variables: LoopsLmxVariables;
135
+ }>(`/api/campaigns/${encodeURIComponent(campaignId)}/preview`);
136
+ const mapColor = createLoopsColorMapper({ color: { "#111111": "#334155" } });
137
+ </script>
138
+
139
+ <template>
140
+ <article>
141
+ <LoopsRenderer server :data="ast" :variables="variables" :config="{ mapColor }" />
142
+ </article>
143
+ </template>
144
+ ```
145
+
146
+ ```vue
147
+ <!-- app/pages/preview/[campaignId].vue -->
148
+ <script setup lang="ts">
149
+ const route = useRoute();
150
+ const campaignId = computed(() => String(route.params.campaignId));
151
+ </script>
152
+
153
+ <template>
154
+ <CampaignPreview :campaign-id="campaignId" />
155
+ </template>
156
+ ```
157
+
158
+ Nuxt serializes the host island's props in a GET URL. Pass only a short public identifier and load
159
+ the campaign and recipient variables inside the island. Implement the example endpoint in the host
160
+ app. It returns `{ ast, variables }` for the authorized viewer and uses
161
+ `Cache-Control: private, no-store`. Nuxt page middleware does not run for component island requests.
162
+ The renderer sets the same header on its island response. Use the shown route rules for personalized
163
+ previews and keep those pages and island responses out of CDN caching. Reload the app when the
164
+ viewer's identity changes because Nuxt can reuse island HTML within the browser session.
165
+
166
+ The island validates and renders the body entirely on the server, with regular HTML anchors and no
167
+ body hydration. Any `config.mapColor` callback defined inside the island stays on the server. A host
168
+ that also uses the regular renderer may still have its client chunks for those other usages.
169
+
102
170
  ## Configuration
103
171
 
104
172
  Module defaults belong in `nuxt.config.ts` under `loopsRenderer`:
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@onderwijsin/nuxt-loops-renderer",
3
3
  "configKey": "loopsRenderer",
4
- "version": "0.3.0",
4
+ "version": "0.4.0",
5
5
  "compatibility": {
6
6
  "nuxt": "^4.0.0"
7
7
  },
package/dist/module.mjs CHANGED
@@ -3,7 +3,7 @@ import { defu } from 'defu';
3
3
  import { enabled, resolveModuleName, resolveLoggerScope, moduleSetup, transpileRuntime, moduleDependenciesWhenEnabled } from '@onderwijsin/nuxt-module-utils/build';
4
4
  import { z } from 'zod';
5
5
 
6
- const version = "0.3.0";
6
+ const version = "0.4.0";
7
7
 
8
8
  const EVALUATE_DEFAULTS = {
9
9
  onMissingVariable: false,
@@ -1,10 +1,12 @@
1
1
  import { type LoopsLmxAst, type LoopsLmxVariables } from "@onderwijsin/loops-core";
2
2
  import type { LoopsRendererConfig } from "../../types.js";
3
3
  type __VLS_Props = {
4
- /** Parsed LMX component tree received from the public campaign-detail API. */
4
+ /** Parsed LMX component tree from a server or campaign-detail API. */
5
5
  data: LoopsLmxAst;
6
6
  variables: LoopsLmxVariables;
7
7
  config?: LoopsRendererConfig;
8
+ /** Render static HTML inside a host-owned Nuxt server component. */
9
+ server?: boolean;
8
10
  };
9
11
  declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
10
12
  declare const _default: typeof __VLS_export;
@@ -1,5 +1,6 @@
1
1
  <script setup>
2
- import { computed, useAppConfig } from "#imports";
2
+ import { useAppConfig, useNuxtApp, useResponseHeader } from "#imports";
3
+ import { computed } from "vue";
3
4
  import {
4
5
  loopsLmxAstSchema,
5
6
  getUnsupportedLoopsLmxNodes,
@@ -11,8 +12,17 @@ import { createLoopsRendererConfig } from "../utils/renderer";
11
12
  const props = defineProps({
12
13
  data: { type: Object, required: true },
13
14
  variables: { type: Object, required: true },
14
- config: { type: Object, required: false }
15
+ config: { type: Object, required: false },
16
+ server: { type: Boolean, required: false }
15
17
  });
18
+ if (props.server) {
19
+ if (!import.meta.server || !useNuxtApp().ssrContext?.islandContext) {
20
+ throw new Error(
21
+ "LoopsRenderer with server enabled must be used inside a Nuxt server component."
22
+ );
23
+ }
24
+ useResponseHeader("Cache-Control").value = "private, no-store";
25
+ }
16
26
  resetLoopsRendererBackground();
17
27
  const appConfig = useAppConfig();
18
28
  const rendererConfig = computed(
@@ -1,10 +1,12 @@
1
1
  import { type LoopsLmxAst, type LoopsLmxVariables } from "@onderwijsin/loops-core";
2
2
  import type { LoopsRendererConfig } from "../../types.js";
3
3
  type __VLS_Props = {
4
- /** Parsed LMX component tree received from the public campaign-detail API. */
4
+ /** Parsed LMX component tree from a server or campaign-detail API. */
5
5
  data: LoopsLmxAst;
6
6
  variables: LoopsLmxVariables;
7
7
  config?: LoopsRendererConfig;
8
+ /** Render static HTML inside a host-owned Nuxt server component. */
9
+ server?: boolean;
8
10
  };
9
11
  declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
10
12
  declare const _default: typeof __VLS_export;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onderwijsin/nuxt-loops-renderer",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Nuxt module for rendering Loops LMX email content.",
5
5
  "homepage": "https://github.com/onderwijsin/nuxt-modules#readme",
6
6
  "bugs": {
@@ -42,7 +42,7 @@
42
42
  "simple-icons": "16.28.0",
43
43
  "tailwindcss": "4.3.3",
44
44
  "zod": "4.4.3",
45
- "@onderwijsin/nuxt-module-utils": "^0.5.1"
45
+ "@onderwijsin/nuxt-module-utils": "^0.5.2"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@nuxt/module-builder": "1.0.3",