@devvit/ui-renderer 0.8.11 → 0.9.1

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.
Files changed (79) hide show
  1. package/blocks/attributes.d.ts +32 -0
  2. package/blocks/attributes.d.ts.map +1 -0
  3. package/blocks/attributes.js +287 -0
  4. package/blocks/index.d.ts +3 -0
  5. package/blocks/index.d.ts.map +1 -0
  6. package/blocks/index.js +2 -0
  7. package/blocks/templates/index.d.ts +13 -0
  8. package/blocks/templates/index.d.ts.map +1 -0
  9. package/blocks/templates/index.js +38 -0
  10. package/blocks/templates/renderAnimationBlock.d.ts +5 -0
  11. package/blocks/templates/renderAnimationBlock.d.ts.map +1 -0
  12. package/blocks/templates/renderAnimationBlock.js +29 -0
  13. package/blocks/templates/renderAvatarBlock.d.ts +5 -0
  14. package/blocks/templates/renderAvatarBlock.d.ts.map +1 -0
  15. package/blocks/templates/renderAvatarBlock.js +29 -0
  16. package/blocks/templates/renderBlock.d.ts +5 -0
  17. package/blocks/templates/renderBlock.d.ts.map +1 -0
  18. package/blocks/templates/renderBlock.js +60 -0
  19. package/blocks/templates/renderButtonBlock.d.ts +5 -0
  20. package/blocks/templates/renderButtonBlock.d.ts.map +1 -0
  21. package/blocks/templates/renderButtonBlock.js +35 -0
  22. package/blocks/templates/renderFullSnooBlock.d.ts +5 -0
  23. package/blocks/templates/renderFullSnooBlock.d.ts.map +1 -0
  24. package/blocks/templates/renderFullSnooBlock.js +29 -0
  25. package/blocks/templates/renderIconBlock.d.ts +5 -0
  26. package/blocks/templates/renderIconBlock.d.ts.map +1 -0
  27. package/blocks/templates/renderIconBlock.js +21 -0
  28. package/blocks/templates/renderImageBlock.d.ts +5 -0
  29. package/blocks/templates/renderImageBlock.d.ts.map +1 -0
  30. package/blocks/templates/renderImageBlock.js +34 -0
  31. package/blocks/templates/renderSpacerBlock.d.ts +5 -0
  32. package/blocks/templates/renderSpacerBlock.d.ts.map +1 -0
  33. package/blocks/templates/renderSpacerBlock.js +20 -0
  34. package/blocks/templates/renderStackBlock.d.ts +5 -0
  35. package/blocks/templates/renderStackBlock.d.ts.map +1 -0
  36. package/blocks/templates/renderStackBlock.js +57 -0
  37. package/blocks/templates/renderTextBlock.d.ts +5 -0
  38. package/blocks/templates/renderTextBlock.d.ts.map +1 -0
  39. package/blocks/templates/renderTextBlock.js +62 -0
  40. package/blocks/templates/renderWebViewBlock.d.ts +5 -0
  41. package/blocks/templates/renderWebViewBlock.d.ts.map +1 -0
  42. package/blocks/templates/renderWebViewBlock.js +39 -0
  43. package/client/assets/snooBlocks.d.ts +2 -0
  44. package/client/assets/snooBlocks.d.ts.map +1 -0
  45. package/client/assets/snooBlocks.js +2 -0
  46. package/client/{renderer.d.ts → blocks.d.ts} +2 -2
  47. package/client/blocks.d.ts.map +1 -0
  48. package/client/{renderer.js → blocks.js} +1 -1
  49. package/client/devvit-animation-player.d.ts +2 -2
  50. package/client/devvit-animation-player.d.ts.map +1 -1
  51. package/client/devvit-animation-player.js +3 -4
  52. package/client/devvit-custom-post.d.ts +25 -0
  53. package/client/devvit-custom-post.d.ts.map +1 -0
  54. package/client/devvit-custom-post.js +147 -0
  55. package/client/effects/devvit-effect-handler.d.ts +18 -0
  56. package/client/effects/devvit-effect-handler.d.ts.map +1 -0
  57. package/client/effects/devvit-effect-handler.js +58 -0
  58. package/client/effects/form-effect-handler.d.ts +9 -0
  59. package/client/effects/form-effect-handler.d.ts.map +1 -0
  60. package/client/effects/form-effect-handler.js +15 -0
  61. package/client/effects/toast-effect-handler.d.ts +6 -0
  62. package/client/effects/toast-effect-handler.d.ts.map +1 -0
  63. package/client/effects/toast-effect-handler.js +12 -0
  64. package/package.json +28 -22
  65. package/server/{renderer.d.ts → blocks.d.ts} +2 -2
  66. package/server/blocks.d.ts.map +1 -0
  67. package/server/{renderer.js → blocks.js} +1 -1
  68. package/styles.css +785 -17
  69. package/styles.d.ts +2 -0
  70. package/styles.d.ts.map +1 -0
  71. package/styles.js +3 -0
  72. package/client/devvit-ui-interactive.d.ts +0 -34
  73. package/client/devvit-ui-interactive.d.ts.map +0 -1
  74. package/client/devvit-ui-interactive.js +0 -229
  75. package/client/renderer.d.ts.map +0 -1
  76. package/render-core.d.ts +0 -20
  77. package/render-core.d.ts.map +0 -1
  78. package/render-core.js +0 -347
  79. package/server/renderer.d.ts.map +0 -1
@@ -0,0 +1,21 @@
1
+ import { nothing } from '@reddit/baseplate/html.js';
2
+ import { getTemplateRenderingStrategy } from '@reddit/faceplate-ui/faceplateUIConfig.js';
3
+ import { defaultClasses, iconSizeClass, onClickAction, sizingClass, stackChildClass, } from '../attributes.js';
4
+ import { classMap } from './index.js';
5
+ export function renderIconBlock(block, ctx) {
6
+ const { html } = getTemplateRenderingStrategy();
7
+ if (!block.config?.iconConfig) {
8
+ console.error('Invalid block: Icon missing IconConfig');
9
+ return nothing;
10
+ }
11
+ const { icon, size, color } = block.config.iconConfig;
12
+ // adopt `icons-all.ts` from faceplate-ui storybook
13
+ const classes = {
14
+ ...defaultClasses(block.type),
15
+ ...stackChildClass(ctx.stackDirection),
16
+ ...sizingClass(block.size),
17
+ ...iconSizeClass(size),
18
+ };
19
+ const onClick = onClickAction(block, ctx);
20
+ return html `<div class="${classMap(classes)}" data-debug-block-type="icon"></div>`;
21
+ }
@@ -0,0 +1,5 @@
1
+ import { TemplateLike } from '@reddit/baseplate/html.js';
2
+ import { Block } from '@devvit/protos';
3
+ import { RenderContext } from './index.js';
4
+ export declare function renderImageBlock(block: Block, ctx: RenderContext): TemplateLike;
5
+ //# sourceMappingURL=renderImageBlock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderImageBlock.d.ts","sourceRoot":"","sources":["../../../src/blocks/templates/renderImageBlock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGlE,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAUvC,OAAO,EAAY,aAAa,EAAE,MAAM,YAAY,CAAC;AAErD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,aAAa,GAAG,YAAY,CAkC/E"}
@@ -0,0 +1,34 @@
1
+ import { nothing } from '@reddit/baseplate/html.js';
2
+ import { getTemplateRenderingStrategy } from '@reddit/faceplate-ui/faceplateUIConfig.js';
3
+ import { defaultClasses, onClickAction, resizeModeClass, sizingClass, sizingStyle, stackChildClass, } from '../attributes.js';
4
+ import { classMap } from './index.js';
5
+ export function renderImageBlock(block, ctx) {
6
+ const { html, styleMap, ifDefined } = getTemplateRenderingStrategy();
7
+ if (!block.config?.imageConfig) {
8
+ console.error('Invalid block: Image missing ImageConfig');
9
+ return nothing;
10
+ }
11
+ const { width, height, url, description, resizeMode } = block.config.imageConfig;
12
+ const classes = {
13
+ ...defaultClasses(block.type),
14
+ ...stackChildClass(ctx.stackDirection),
15
+ ...sizingClass(block.size),
16
+ ...resizeModeClass(resizeMode),
17
+ };
18
+ const styles = {
19
+ ...sizingStyle(block.size),
20
+ };
21
+ const onClick = onClickAction(block, ctx);
22
+ return html `
23
+ <img
24
+ src="${url}"
25
+ width="${width}"
26
+ height="${height}"
27
+ alt="${description}"
28
+ class="${classMap(classes)}"
29
+ style="${styleMap(styles)}"
30
+ @click="${ifDefined(onClick)}"
31
+ data-debug-block-type="image"
32
+ />
33
+ `;
34
+ }
@@ -0,0 +1,5 @@
1
+ import { TemplateLike } from '@reddit/baseplate/html.js';
2
+ import { Block } from '@devvit/protos';
3
+ import { RenderContext } from './index.js';
4
+ export declare function renderSpacerBlock(block: Block, ctx: RenderContext): TemplateLike;
5
+ //# sourceMappingURL=renderSpacerBlock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderSpacerBlock.d.ts","sourceRoot":"","sources":["../../../src/blocks/templates/renderSpacerBlock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGzD,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AASvC,OAAO,EAAY,aAAa,EAAE,MAAM,YAAY,CAAC;AAErD,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,aAAa,GAAG,YAAY,CAmBhF"}
@@ -0,0 +1,20 @@
1
+ import { getTemplateRenderingStrategy } from '@reddit/faceplate-ui/faceplateUIConfig.js';
2
+ import { defaultClasses, sizingClass, sizingStyle, spacerSizeClass, stackChildClass, } from '../attributes.js';
3
+ import { classMap } from './index.js';
4
+ export function renderSpacerBlock(block, ctx) {
5
+ const { html, styleMap } = getTemplateRenderingStrategy();
6
+ const classes = {
7
+ ...defaultClasses(block.type),
8
+ ...stackChildClass(ctx.stackDirection),
9
+ ...sizingClass(block.size),
10
+ ...spacerSizeClass(block.config?.spacerConfig?.size, ctx.stackDirection),
11
+ };
12
+ const styles = {
13
+ ...sizingStyle(block.size),
14
+ };
15
+ return html `<div
16
+ class="${classMap(classes)}"
17
+ style="${styleMap(styles)}"
18
+ data-debug-block-type="spacer"
19
+ ></div>`;
20
+ }
@@ -0,0 +1,5 @@
1
+ import { TemplateLike } from '@reddit/baseplate/html.js';
2
+ import { Block } from '@devvit/protos';
3
+ import { RenderContext } from './index.js';
4
+ export declare function renderStackBlock(block: Block, ctx?: RenderContext): TemplateLike;
5
+ //# sourceMappingURL=renderStackBlock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderStackBlock.d.ts","sourceRoot":"","sources":["../../../src/blocks/templates/renderStackBlock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGlE,OAAO,EAAE,KAAK,EAAuB,MAAM,gBAAgB,CAAC;AAkB5D,OAAO,EAAY,aAAa,EAAE,MAAM,YAAY,CAAC;AAErD,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,KAAK,EACZ,GAAG,GAAE,aAAoE,GACxE,YAAY,CAoEd"}
@@ -0,0 +1,57 @@
1
+ import { nothing } from '@reddit/baseplate/html.js';
2
+ import { getTemplateRenderingStrategy } from '@reddit/faceplate-ui/faceplateUIConfig.js';
3
+ import { BlockStackDirection } from '@devvit/protos';
4
+ import { alignmentClass, backgroundStyle, borderClass, borderStyle, defaultClasses, gapClass, onClickAction, paddingClass, radiusClass, sizingClass, sizingStyle, stackChildClass, stackDirectionClass, } from '../attributes.js';
5
+ import { renderBlock } from './renderBlock.js';
6
+ import { classMap } from './index.js';
7
+ export function renderStackBlock(block, ctx = { stackDirection: BlockStackDirection.UNRECOGNIZED }) {
8
+ const { html, repeat, styleMap, ifDefined } = getTemplateRenderingStrategy();
9
+ if (block.config?.stackConfig === undefined) {
10
+ console.error('Invalid block: Stack missing StackConfig');
11
+ return nothing;
12
+ }
13
+ const { children, direction, padding, gap, alignment, reverse, backgroundColor, border, cornerRadius, } = block.config.stackConfig;
14
+ const classes = {
15
+ ...defaultClasses(block.type),
16
+ ...stackDirectionClass(direction, reverse),
17
+ ...stackChildClass(ctx.stackDirection),
18
+ ...sizingClass(block.size),
19
+ ...paddingClass(padding),
20
+ ...gapClass(gap),
21
+ ...alignmentClass(direction, alignment),
22
+ ...borderClass(border),
23
+ ...radiusClass(cornerRadius),
24
+ };
25
+ const styles = {
26
+ ...sizingStyle(block.size),
27
+ ...backgroundStyle(backgroundColor),
28
+ ...borderStyle(border),
29
+ };
30
+ const newCtx = {
31
+ ...ctx,
32
+ stackDirection: direction,
33
+ };
34
+ const onClick = onClickAction(block, ctx);
35
+ let blockType = '';
36
+ switch (direction) {
37
+ case BlockStackDirection.STACK_DEPTH:
38
+ blockType = 'zstack';
39
+ break;
40
+ case BlockStackDirection.STACK_VERTICAL:
41
+ blockType = 'vstack';
42
+ break;
43
+ case BlockStackDirection.STACK_HORIZONTAL:
44
+ blockType = 'hstack';
45
+ break;
46
+ }
47
+ return html `
48
+ <div
49
+ class="${classMap(classes)}"
50
+ style="${styleMap(styles)}"
51
+ @click="${ifDefined(onClick)}"
52
+ data-debug-block-type="${blockType}"
53
+ >
54
+ ${repeat(children, (block) => renderBlock(block, newCtx))}
55
+ </div>
56
+ `;
57
+ }
@@ -0,0 +1,5 @@
1
+ import { TemplateLike } from '@reddit/baseplate/html.js';
2
+ import { Block } from '@devvit/protos';
3
+ import { RenderContext } from './index.js';
4
+ export declare function renderTextBlock(block: Block, ctx: RenderContext): TemplateLike;
5
+ //# sourceMappingURL=renderTextBlock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderTextBlock.d.ts","sourceRoot":"","sources":["../../../src/blocks/templates/renderTextBlock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGlE,OAAO,EAAE,KAAK,EAAkD,MAAM,gBAAgB,CAAC;AAavF,OAAO,EAAY,aAAa,EAAE,MAAM,YAAY,CAAC;AAErD,wBAAgB,eAAe,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,aAAa,GAAG,YAAY,CA+D9E"}
@@ -0,0 +1,62 @@
1
+ import { nothing } from '@reddit/baseplate/html.js';
2
+ import { getTemplateRenderingStrategy } from '@reddit/faceplate-ui/faceplateUIConfig.js';
3
+ import { BlockTextSize, BlockTextStyle, BlockTextWeight } from '@devvit/protos';
4
+ import { colorStyle, defaultClasses, onClickAction, sizingClass, stackChildClass, textAlignClass, textOutlineClass, textSizeClass, textWeightClass, } from '../attributes.js';
5
+ import { classMap } from './index.js';
6
+ export function renderTextBlock(block, ctx) {
7
+ const { html, styleMap, ifDefined } = getTemplateRenderingStrategy();
8
+ if (!block.config?.textConfig) {
9
+ console.error('Invalid block: Text missing TextConfig');
10
+ return nothing;
11
+ }
12
+ const { text, color, size, alignment, weight, style, outline } = block.config.textConfig;
13
+ let textColor = 'neutral-content';
14
+ let baseStyle = {};
15
+ switch (style) {
16
+ case BlockTextStyle.TEXT_STYLE_METADATA:
17
+ textColor = 'neutral-content-weak';
18
+ baseStyle = {
19
+ ...textSizeClass(BlockTextSize.TEXT_SIZE_SMALL),
20
+ ...textWeightClass(BlockTextWeight.TEXT_WEIGHT_REGULAR),
21
+ };
22
+ break;
23
+ case BlockTextStyle.TEXT_STYLE_BODY:
24
+ textColor = 'neutral-content';
25
+ baseStyle = {
26
+ ...textSizeClass(BlockTextSize.TEXT_SIZE_MEDIUM),
27
+ ...textWeightClass(BlockTextWeight.TEXT_WEIGHT_REGULAR),
28
+ };
29
+ break;
30
+ case BlockTextStyle.TEXT_STYLE_HEADING:
31
+ textColor = 'neutral-content-strong';
32
+ baseStyle = {
33
+ ...textSizeClass(BlockTextSize.TEXT_SIZE_LARGE),
34
+ ...textWeightClass(BlockTextWeight.TEXT_WEIGHT_BOLD),
35
+ };
36
+ break;
37
+ }
38
+ textColor = color ?? textColor;
39
+ const styles = {
40
+ ...colorStyle(textColor),
41
+ };
42
+ const classes = {
43
+ ...defaultClasses(block.type),
44
+ ...baseStyle,
45
+ ...stackChildClass(ctx.stackDirection),
46
+ ...sizingClass(block.size),
47
+ ...textSizeClass(size),
48
+ ...textAlignClass(alignment),
49
+ ...textWeightClass(weight),
50
+ };
51
+ if (outline !== undefined) {
52
+ Object.assign(classes, textOutlineClass(outline, textColor));
53
+ }
54
+ const onClick = onClickAction(block, ctx);
55
+ return html `<span
56
+ class="${classMap(classes)}"
57
+ style="${styleMap(styles)}"
58
+ @click="${ifDefined(onClick)}"
59
+ data-debug-block-type="text"
60
+ >${text}</span
61
+ >`;
62
+ }
@@ -0,0 +1,5 @@
1
+ import { TemplateLike } from '@reddit/baseplate/html.js';
2
+ import { Block } from '@devvit/protos';
3
+ import { RenderContext } from './index.js';
4
+ export declare function renderWebViewBlock(block: Block, ctx: RenderContext): TemplateLike;
5
+ //# sourceMappingURL=renderWebViewBlock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderWebViewBlock.d.ts","sourceRoot":"","sources":["../../../src/blocks/templates/renderWebViewBlock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGlE,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAGvC,OAAO,EAAY,aAAa,EAAE,MAAM,YAAY,CAAC;AASrD,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,aAAa,GAAG,YAAY,CAmCjF"}
@@ -0,0 +1,39 @@
1
+ import { nothing } from '@reddit/baseplate/html.js';
2
+ import { getTemplateRenderingStrategy } from '@reddit/faceplate-ui/faceplateUIConfig.js';
3
+ import { defaultClasses, sizingClass, sizingStyle, stackChildClass } from '../attributes.js';
4
+ import { classMap } from './index.js';
5
+ const iframeRefs = {};
6
+ const postMessage = (src, ctx) => {
7
+ const iframe = iframeRefs[src];
8
+ iframe?.contentWindow?.postMessage(ctx, '*');
9
+ };
10
+ export function renderWebViewBlock(block, ctx) {
11
+ const { html, styleMap } = getTemplateRenderingStrategy();
12
+ if (!block.config?.webviewConfig) {
13
+ console.error('Invalid block: WebView missing WebViewConfig');
14
+ return nothing;
15
+ }
16
+ const { url } = block.config.webviewConfig;
17
+ const classes = {
18
+ ...defaultClasses(block.type),
19
+ ...stackChildClass(ctx.stackDirection),
20
+ ...sizingClass(block.size),
21
+ };
22
+ const styles = {
23
+ ...sizingStyle(block.size),
24
+ };
25
+ const onLoad = (evt) => {
26
+ iframeRefs[url] = evt.target;
27
+ postMessage(url, ctx);
28
+ };
29
+ const saveRef = (el) => (iframeRefs[url] = el);
30
+ return html `<iframe
31
+ src="${url}"
32
+ sandbox="allow-scripts"
33
+ class="${classMap(classes)}"
34
+ style="${styleMap(styles)}"
35
+ @load="${onLoad}"
36
+ ref="${saveRef}"
37
+ data-debug-block-type="webview"
38
+ ></iframe>`;
39
+ }
@@ -0,0 +1,2 @@
1
+ export declare const snooBlocks: import("lit-html").TemplateResult<2>;
2
+ //# sourceMappingURL=snooBlocks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snooBlocks.d.ts","sourceRoot":"","sources":["../../../src/client/assets/snooBlocks.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU,sCAAy37K,CAAC"}