@crombolo/render 0.48.1 → 0.50.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crombolo/render",
3
- "version": "0.48.1",
3
+ "version": "0.50.0",
4
4
  "description": "Internal to crombolo, with no compatibility promise: use @crombolo/crombolo. TSX server rendering and the published-content model for crombolo.",
5
5
  "license": "MIT",
6
6
  "author": "Crombolo",
@@ -34,8 +34,8 @@
34
34
  "access": "public"
35
35
  },
36
36
  "dependencies": {
37
- "@crombolo/common": "0.48.1",
38
- "@crombolo/core": "0.48.1",
37
+ "@crombolo/common": "0.50.0",
38
+ "@crombolo/core": "0.50.0",
39
39
  "@types/react": "^19.3.0"
40
40
  }
41
41
  }
package/src/gap.ts ADDED
@@ -0,0 +1,30 @@
1
+ /**
2
+ * A marked gap in a template (story 281): where a part could not be carried over,
3
+ * visitors see the rest of the page and an editor's preview says what is missing.
4
+ */
5
+ import { isPreview } from './context.ts'
6
+ import { escapeHtml, RawHtml } from './html.ts'
7
+ import { type Child, renderToString } from './jsx-runtime.ts'
8
+
9
+ export interface GapProps {
10
+ /** Why this part is missing. */
11
+ reason: string
12
+ /** What used to be here. */
13
+ was?: string
14
+ /** What visitors see in its place, if anything. */
15
+ children?: Child
16
+ }
17
+
18
+ // A span, so a gap inside a paragraph does not close the paragraph.
19
+ const BOX =
20
+ 'display: block; box-sizing: border-box; min-height: 96px; padding: 12px; background: #e5e7eb; border: 1px dashed #6b7280; color: #374151; font: 14px sans-serif;'
21
+
22
+ /** Its children or nothing to visitors; in preview, a box saying what is missing. */
23
+ export async function Gap(props: GapProps): Promise<RawHtml> {
24
+ const children = await renderToString(props.children)
25
+ if (!isPreview()) return new RawHtml(children)
26
+ const was = props.was ? `<span style="display: block;">Was: ${escapeHtml(props.was)}</span>` : ''
27
+ return new RawHtml(
28
+ `<span class="crombolo-gap" style="${BOX}"><span style="display: block;"><strong>Missing:</strong> ${escapeHtml(props.reason)}</span>${was}<span style="display: block;">Visitors don't see this box.</span>${children}</span>`,
29
+ )
30
+ }
package/src/index.ts CHANGED
@@ -9,6 +9,7 @@ export * from './email.ts'
9
9
  export * from './excerpt.ts'
10
10
  export * from './form-script.ts'
11
11
  export * from './forms.ts'
12
+ export * from './gap.ts'
12
13
  export * from './html.ts'
13
14
  export * from './islands.ts'
14
15
  export * from './islands-loader.ts'