@devvit/ui-renderer 0.8.11 → 0.9.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.
Files changed (77) hide show
  1. package/blocks/attributes.d.ts +30 -0
  2. package/blocks/attributes.d.ts.map +1 -0
  3. package/blocks/attributes.js +275 -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 +37 -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 +26 -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 +26 -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 +39 -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 +26 -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 +26 -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 +17 -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 +31 -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 +14 -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 +38 -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 +59 -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 +36 -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 +11 -10
  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 +42 -1
  69. package/tailwind.devvit.cjs +15 -0
  70. package/client/devvit-ui-interactive.d.ts +0 -34
  71. package/client/devvit-ui-interactive.d.ts.map +0 -1
  72. package/client/devvit-ui-interactive.js +0 -229
  73. package/client/renderer.d.ts.map +0 -1
  74. package/render-core.d.ts +0 -20
  75. package/render-core.d.ts.map +0 -1
  76. package/render-core.js +0 -347
  77. package/server/renderer.d.ts.map +0 -1
@@ -0,0 +1,30 @@
1
+ import { ClassInfo } from 'lit/directives/class-map.js';
2
+ import { StyleInfo } from 'lit/directives/style-map.js';
3
+ import { ButtonAppearance, ButtonSize } from '@reddit/faceplate-ui/templates/button.js';
4
+ import { Block, BlockAlignment, BlockAvatarFacing, BlockAvatarSize, BlockBorder, BlockButtonAppearance, BlockButtonSize, BlockFullSnooSize, BlockGap, BlockIconSize, BlockImageResizeMode, BlockPadding, BlockRadius, BlockSize, BlockSpacerSize, BlockStackDirection, BlockTextOutline, BlockTextSize, BlockTextWeight } from '@devvit/protos';
5
+ import { RenderContext } from './templates/index.js';
6
+ export declare function stackDirectionClass(direction: BlockStackDirection, reverse: boolean | undefined): ClassInfo;
7
+ export declare function sizingClass(sizing: BlockSize | undefined): ClassInfo;
8
+ export declare function sizingStyle(sizing: BlockSize | undefined): StyleInfo;
9
+ export declare function paddingClass(padding: BlockPadding | undefined): ClassInfo;
10
+ export declare function gapClass(spacing: BlockGap | undefined): ClassInfo;
11
+ export declare function alignmentClass(direction: BlockStackDirection, align: BlockAlignment | undefined): ClassInfo;
12
+ export declare function backgroundStyle(background: string | undefined): StyleInfo;
13
+ export declare function borderClass(border: BlockBorder | undefined): ClassInfo;
14
+ export declare function borderStyle(border: BlockBorder | undefined): StyleInfo;
15
+ export declare function radiusClass(radius: BlockRadius | undefined): ClassInfo;
16
+ export declare function textSizeClass(size: BlockTextSize | undefined): ClassInfo;
17
+ export declare function textAlignClass(alignment: BlockAlignment | undefined): ClassInfo;
18
+ export declare function textWeightClass(weight: BlockTextWeight | undefined): ClassInfo;
19
+ export declare function textOutlineClass(outline: BlockTextOutline, _textColor: string | undefined): ClassInfo;
20
+ export declare function colorStyle(color: string | undefined): StyleInfo;
21
+ export declare function spacerSizeClass(size: BlockSpacerSize | undefined, stackDirection: BlockStackDirection): ClassInfo;
22
+ export declare function resizeModeClass(resizeMode: BlockImageResizeMode | undefined): ClassInfo;
23
+ export declare function iconSizeClass(size: BlockIconSize | undefined): ClassInfo;
24
+ export declare function avatarSizeClass(size: BlockAvatarSize | undefined): ClassInfo;
25
+ export declare function facingClass(facing: BlockAvatarFacing | undefined): ClassInfo;
26
+ export declare function fullSnooSizeClass(size: BlockFullSnooSize | undefined): ClassInfo;
27
+ export declare function buttonAppearance(appearance: BlockButtonAppearance | undefined): ButtonAppearance;
28
+ export declare function buttonSize(size: BlockButtonSize | undefined): ButtonSize;
29
+ export declare function onClickAction(block: Block, ctx: RenderContext): (() => void) | undefined;
30
+ //# sourceMappingURL=attributes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attributes.d.ts","sourceRoot":"","sources":["../../src/blocks/attributes.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,275 @@
1
+ import { ButtonSize } from '@reddit/faceplate-ui/templates/button.js';
2
+ import { BlockActionType, BlockAvatarFacing, BlockAvatarSize, BlockBorderWidth, BlockButtonAppearance, BlockButtonSize, BlockFullSnooSize, BlockGap, BlockHorizontalAlignment, BlockIconSize, BlockImageResizeMode, BlockPadding, BlockRadius, BlockSpacerSize, BlockStackDirection, BlockTextOutline, BlockTextSize, BlockTextWeight, BlockVerticalAlignment, } from '@devvit/protos';
3
+ function findColor(color) {
4
+ // TODO: check CSS for color var and wrap in var(--color-${background}-background)
5
+ // - will need access to shadow root
6
+ return color;
7
+ }
8
+ export function stackDirectionClass(direction, reverse) {
9
+ const vstack = direction === BlockStackDirection.STACK_VERTICAL;
10
+ const hstack = direction === BlockStackDirection.STACK_HORIZONTAL;
11
+ const zstack = direction === BlockStackDirection.STACK_DEPTH;
12
+ return {
13
+ flex: vstack || hstack,
14
+ 'flex-row': hstack,
15
+ 'flex-row-reverse': hstack && reverse === true,
16
+ 'flex-col': vstack,
17
+ 'flex-col-reverse': vstack && reverse === true,
18
+ 'devvit-depth': zstack,
19
+ };
20
+ }
21
+ export function sizingClass(sizing) {
22
+ return {
23
+ grow: sizing?.grow === true,
24
+ };
25
+ }
26
+ export function sizingStyle(sizing) {
27
+ return {
28
+ width: sizing?.width === undefined ? undefined : `${sizing.width}%`,
29
+ height: sizing?.height === undefined ? undefined : `${sizing.height}%`,
30
+ };
31
+ }
32
+ export function paddingClass(padding) {
33
+ return {
34
+ 'p-0': padding === undefined || padding == BlockPadding.PADDING_NONE,
35
+ 'p-2xs': padding === BlockPadding.PADDING_XSMALL,
36
+ 'p-xs': padding === BlockPadding.PADDING_SMALL,
37
+ 'p-md': padding === BlockPadding.PADDING_MEDIUM,
38
+ 'p-xl': padding === BlockPadding.PADDING_LARGE,
39
+ };
40
+ }
41
+ export function gapClass(spacing) {
42
+ return {
43
+ 'gap-0': spacing === undefined || spacing === BlockGap.GAP_NONE,
44
+ 'gap-xs': spacing === BlockGap.GAP_SMALL,
45
+ 'gap-md': spacing === BlockGap.GAP_MEDIUM,
46
+ 'gap-xl': spacing === BlockGap.GAP_LARGE,
47
+ };
48
+ }
49
+ export function alignmentClass(direction, align) {
50
+ const hstack = direction === BlockStackDirection.STACK_HORIZONTAL;
51
+ const vstack = direction === BlockStackDirection.STACK_VERTICAL;
52
+ const zstack = direction === BlockStackDirection.STACK_DEPTH;
53
+ const hnone = align === undefined || align.horizontal === undefined;
54
+ const start = align?.horizontal === BlockHorizontalAlignment.ALIGN_START;
55
+ const center = align?.horizontal === BlockHorizontalAlignment.ALIGN_CENTER;
56
+ const end = align?.horizontal === BlockHorizontalAlignment.ALIGN_END;
57
+ const vnone = align === undefined || align.vertical === undefined;
58
+ const top = align?.vertical === BlockVerticalAlignment.ALIGN_TOP;
59
+ const middle = align?.vertical === BlockVerticalAlignment.ALIGN_MIDDLE;
60
+ const bottom = align?.vertical === BlockVerticalAlignment.ALIGN_BOTTOM;
61
+ return {
62
+ // Primary axis alignment
63
+ 'justify-start': (start && hstack) || (top && vstack),
64
+ 'justify-center': (center && hstack) || (middle && vstack),
65
+ 'justify-end': (end && hstack) || (bottom && vstack),
66
+ // Alternate for ZStack
67
+ 'justify-items-start': start && zstack,
68
+ 'justify-items-center': center && zstack,
69
+ 'justify-items-end': end && zstack,
70
+ // Cross-axis alignment
71
+ 'items-start': (top && hstack) || (start && vstack),
72
+ 'items-center': (middle && hstack) || (center && vstack),
73
+ 'items-stretch': (vnone && hstack) || (hnone && vstack),
74
+ 'items-end': (bottom && hstack) || (end && vstack),
75
+ // Alternate for ZStack
76
+ 'content-start': top && zstack,
77
+ 'content-center': middle && zstack,
78
+ 'content-end': bottom && zstack,
79
+ };
80
+ }
81
+ export function backgroundStyle(background) {
82
+ return {
83
+ backgroundColor: findColor(background),
84
+ };
85
+ }
86
+ export function borderClass(border) {
87
+ const hasBorder = border !== undefined && border.width !== BlockBorderWidth.BORDER_WIDTH_NONE;
88
+ return {
89
+ 'border-0': !hasBorder,
90
+ 'border-solid': hasBorder,
91
+ 'border-dx-thin': border?.width === BlockBorderWidth.BORDER_WIDTH_THIN,
92
+ 'border-dx-thick': border?.width === BlockBorderWidth.BORDER_WIDTH_THICK,
93
+ 'border-neutral-border': border !== undefined &&
94
+ border.width !== BlockBorderWidth.BORDER_WIDTH_NONE &&
95
+ border.color === undefined,
96
+ };
97
+ }
98
+ export function borderStyle(border) {
99
+ return {
100
+ borderColor: border?.color, // TODO: check CSS for color var and wrap in var(--color-${border.color}-background)
101
+ };
102
+ }
103
+ export function radiusClass(radius) {
104
+ return {
105
+ 'rounded-none': radius === undefined || radius === BlockRadius.RADIUS_NONE,
106
+ 'rounded-dx-sm': radius === BlockRadius.RADIUS_SMALL,
107
+ 'rounded-dx-md': radius === BlockRadius.RADIUS_MEDIUM,
108
+ 'rounded-dx-lg': radius === BlockRadius.RADIUS_LARGE,
109
+ 'rounded-full': radius === BlockRadius.RADIUS_FULL,
110
+ };
111
+ }
112
+ export function textSizeClass(size) {
113
+ return {
114
+ 'text-10': size === BlockTextSize.TEXT_SIZE_XSMALL,
115
+ 'text-12': size === BlockTextSize.TEXT_SIZE_SMALL,
116
+ 'text-14': size === undefined || size === BlockTextSize.TEXT_SIZE_MEDIUM,
117
+ 'text-16': size === BlockTextSize.TEXT_SIZE_LARGE,
118
+ 'text-18': size === BlockTextSize.TEXT_SIZE_XLARGE,
119
+ 'text-24': size === BlockTextSize.TEXT_SIZE_XXLARGE,
120
+ };
121
+ }
122
+ export function textAlignClass(alignment) {
123
+ return {
124
+ 'text-start': alignment === undefined ||
125
+ alignment.horizontal === undefined ||
126
+ alignment.horizontal === BlockHorizontalAlignment.ALIGN_START,
127
+ 'text-center': alignment?.horizontal === BlockHorizontalAlignment.ALIGN_CENTER,
128
+ 'text-end': alignment?.horizontal === BlockHorizontalAlignment.ALIGN_END,
129
+ };
130
+ }
131
+ export function textWeightClass(weight) {
132
+ return {
133
+ 'font-normal': weight === undefined || weight === BlockTextWeight.TEXT_WEIGHT_REGULAR,
134
+ 'font-semibold': weight === BlockTextWeight.TEXT_WEIGHT_BOLD,
135
+ };
136
+ }
137
+ export function textOutlineClass(outline, _textColor) {
138
+ const thin = outline === BlockTextOutline.TEXT_OUTLINE_THIN;
139
+ const thick = outline === BlockTextOutline.TEXT_OUTLINE_THICK;
140
+ // TODO: hook into host lit element to determine final color and apply bright/dark outline
141
+ return {
142
+ 'text-outline-thin-bright': thin,
143
+ 'text-outline-thick-bright': thick,
144
+ };
145
+ }
146
+ export function colorStyle(color) {
147
+ return {
148
+ color: findColor(color),
149
+ };
150
+ }
151
+ export function spacerSizeClass(size, stackDirection) {
152
+ const xsmall = size === BlockSpacerSize.SPACER_XSMALL;
153
+ const small = size === BlockSpacerSize.SPACER_SMALL;
154
+ const medium = size === BlockSpacerSize.SPACER_MEDIUM;
155
+ const large = size === BlockSpacerSize.SPACER_LARGE;
156
+ const vstack = stackDirection === BlockStackDirection.STACK_VERTICAL;
157
+ const hstack = stackDirection === BlockStackDirection.STACK_HORIZONTAL;
158
+ return {
159
+ 'w-2xs': xsmall && hstack,
160
+ 'w-xs': small && hstack,
161
+ 'w-md': medium && hstack,
162
+ 'w-xl': large && hstack,
163
+ 'h-2xs': xsmall && vstack,
164
+ 'h-xs': small && vstack,
165
+ 'h-md': medium && vstack,
166
+ 'h-xl': large && vstack,
167
+ };
168
+ }
169
+ export function resizeModeClass(resizeMode) {
170
+ return {
171
+ 'object-contain': resizeMode === undefined || resizeMode === BlockImageResizeMode.IMAGE_RESIZE_FIT,
172
+ 'object-none': resizeMode === BlockImageResizeMode.IMAGE_RESIZE_NONE,
173
+ 'object-cover': resizeMode === BlockImageResizeMode.IMAGE_RESIZE_COVER,
174
+ 'object-fill': resizeMode === BlockImageResizeMode.IMAGE_RESIZE_FILL,
175
+ 'object-scale-down': resizeMode === BlockImageResizeMode.IMAGE_RESIZE_SCALE_DOWN,
176
+ };
177
+ }
178
+ export function iconSizeClass(size) {
179
+ return {
180
+ 'w-sm h-sm': size === BlockIconSize.ICON_SIZE_XSMALL,
181
+ 'w-md h-md': size === BlockIconSize.ICON_SIZE_SMALL,
182
+ 'w-[1.25rem] h-[1.25rem]': size === BlockIconSize.ICON_SIZE_MEDIUM,
183
+ 'w-lg h-lg': size === BlockIconSize.ICON_SIZE_LARGE,
184
+ };
185
+ }
186
+ export function avatarSizeClass(size) {
187
+ return {
188
+ 'aspect-square': true,
189
+ 'w-md': size === BlockAvatarSize.AVATAR_SIZE_XXSMALL,
190
+ 'w-lg': size === BlockAvatarSize.AVATAR_SIZE_XSMALL,
191
+ 'w-xl': size === undefined || size === BlockAvatarSize.AVATAR_SIZE_SMALL,
192
+ 'w-[2.5rem]': size === BlockAvatarSize.AVATAR_SIZE_MEDIUM,
193
+ 'w-2xl': size === BlockAvatarSize.AVATAR_SIZE_LARGE,
194
+ 'w-[3.5rem]': size === BlockAvatarSize.AVATAR_SIZE_XLARGE,
195
+ 'w-3xl': size === BlockAvatarSize.AVATAR_SIZE_XXLARGE,
196
+ 'w-[5.5rem]': size === BlockAvatarSize.AVATAR_SIZE_XXXLARGE,
197
+ };
198
+ }
199
+ export function facingClass(facing) {
200
+ return {
201
+ 'scale-x-100': facing === undefined || facing === BlockAvatarFacing.AVATAR_FACING_RIGHT,
202
+ '-scale-x-100': facing === BlockAvatarFacing.AVATAR_FACING_LEFT,
203
+ };
204
+ }
205
+ export function fullSnooSizeClass(size) {
206
+ const xsmall = size === BlockFullSnooSize.FULLSNOO_XSMALL;
207
+ const small = size === BlockFullSnooSize.FULLSNOO_SMALL;
208
+ const medium = size === BlockFullSnooSize.FULLSNOO_MEDIUM;
209
+ const large = size === BlockFullSnooSize.FULLSNOO_LARGE;
210
+ const xlarge = size === BlockFullSnooSize.FULLSNOO_XLARGE;
211
+ const xxlarge = size === BlockFullSnooSize.FULLSNOO_XXLARGE;
212
+ return {
213
+ 'aspect-square': true,
214
+ 'w-2xl': xsmall,
215
+ 'w-3xl': size === undefined || small,
216
+ 'w-[5.5rem]': medium,
217
+ 'w-[9rem]': large,
218
+ 'w-[12rem]': xlarge,
219
+ 'w-[20rem]': xxlarge,
220
+ };
221
+ }
222
+ export function buttonAppearance(appearance) {
223
+ let buttonAppearance;
224
+ switch (appearance) {
225
+ case BlockButtonAppearance.BUTTON_APPEARANCE_PRIMARY:
226
+ buttonAppearance = 'primary';
227
+ break;
228
+ case BlockButtonAppearance.BUTTON_APPEARANCE_PLAIN:
229
+ buttonAppearance = 'plain';
230
+ break;
231
+ case BlockButtonAppearance.BUTTON_APPEARANCE_BORDERED:
232
+ buttonAppearance = 'bordered';
233
+ break;
234
+ case BlockButtonAppearance.BUTTON_APPEARANCE_MEDIA:
235
+ buttonAppearance = 'media';
236
+ break;
237
+ case BlockButtonAppearance.BUTTON_APPEARANCE_SUCCESS:
238
+ buttonAppearance = 'success';
239
+ break;
240
+ case BlockButtonAppearance.BUTTON_APPEARANCE_DESTRUCTIVE:
241
+ buttonAppearance = 'destructive';
242
+ break;
243
+ case BlockButtonAppearance.BUTTON_APPEARANCE_SECONDARY:
244
+ default:
245
+ buttonAppearance = 'secondary';
246
+ break;
247
+ }
248
+ return buttonAppearance;
249
+ }
250
+ export function buttonSize(size) {
251
+ let buttonSize;
252
+ switch (size) {
253
+ case BlockButtonSize.BUTTON_SIZE_SMALL:
254
+ buttonSize = ButtonSize.Small;
255
+ break;
256
+ case BlockButtonSize.BUTTON_SIZE_LARGE:
257
+ buttonSize = ButtonSize.Large;
258
+ break;
259
+ case BlockButtonSize.BUTTON_SIZE_MEDIUM:
260
+ default:
261
+ buttonSize = ButtonSize.Medium;
262
+ break;
263
+ }
264
+ return buttonSize;
265
+ }
266
+ export function onClickAction(block, ctx) {
267
+ const clickAction = block.actions.find((a) => a.type === BlockActionType.ACTION_CLICK);
268
+ if (clickAction) {
269
+ return () => {
270
+ if (ctx.onAction) {
271
+ ctx.onAction(clickAction);
272
+ }
273
+ };
274
+ }
275
+ }
@@ -0,0 +1,3 @@
1
+ /// <reference lib="dom" />
2
+ export * from './templates/index.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/blocks/index.ts"],"names":[],"mappings":";AAEA,cAAc,sBAAsB,CAAC"}
@@ -0,0 +1,2 @@
1
+ /// <reference lib="dom"/>
2
+ export * from './templates/index.js';
@@ -0,0 +1,13 @@
1
+ import { classMap as clientClassMap } from 'lit/directives/class-map.js';
2
+ import { TemplateLike, UnsafeString } from '@reddit/baseplate/html.js';
3
+ import { Block, BlockAction, BlockRenderResponse, BlockStackDirection } from '@devvit/protos';
4
+ import { ClassInfo } from 'lit/directives/class-map.js';
5
+ export interface RenderContext {
6
+ blockRender?: BlockRenderResponse | undefined;
7
+ state?: unknown | undefined;
8
+ stackDirection: BlockStackDirection;
9
+ onAction?: ((action: BlockAction) => void) | undefined;
10
+ }
11
+ export declare function renderBlocks(block: Block, context?: Partial<RenderContext>): TemplateLike;
12
+ export declare function classMap(classInfo: ClassInfo): UnsafeString | ReturnType<typeof clientClassMap>;
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/blocks/templates/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAEzE,OAAO,EAAW,YAAY,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEhF,OAAO,EACL,KAAK,EACL,WAAW,EACX,mBAAmB,EACnB,mBAAmB,EAEpB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAGxD,MAAM,WAAW,aAAa;IAC5B,WAAW,CAAC,EAAE,mBAAmB,GAAG,SAAS,CAAC;IAC9C,KAAK,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC5B,cAAc,EAAE,mBAAmB,CAAC;IACpC,QAAQ,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,WAAW,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;CACxD;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,GAAE,OAAO,CAAC,aAAa,CAAM,GAAG,YAAY,CAsB7F;AAED,wBAAgB,QAAQ,CAAC,SAAS,EAAE,SAAS,GAAG,YAAY,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAe/F"}
@@ -0,0 +1,37 @@
1
+ import { classMap as clientClassMap } from 'lit/directives/class-map.js';
2
+ import { nothing } from '@reddit/baseplate/html.js';
3
+ import { BlockStackDirection, BlockType, } from '@devvit/protos';
4
+ import { renderBlock } from './renderBlock.js';
5
+ import { getTemplateRenderingStrategy } from '@reddit/faceplate-ui/faceplateUIConfig.js';
6
+ export function renderBlocks(block, context = {}) {
7
+ if (block.type !== BlockType.BLOCK_ROOT) {
8
+ console.error('Invalid root block');
9
+ return nothing;
10
+ }
11
+ return renderBlock({
12
+ type: BlockType.BLOCK_STACK,
13
+ config: {
14
+ stackConfig: {
15
+ direction: BlockStackDirection.STACK_VERTICAL,
16
+ children: block.config?.rootConfig?.children ?? [],
17
+ },
18
+ },
19
+ actions: [],
20
+ }, {
21
+ ...context,
22
+ stackDirection: BlockStackDirection.UNRECOGNIZED,
23
+ });
24
+ }
25
+ export function classMap(classInfo) {
26
+ const { getType } = getTemplateRenderingStrategy();
27
+ if (getType() === 'client') {
28
+ return clientClassMap(classInfo);
29
+ }
30
+ let result = '';
31
+ for (const name in classInfo) {
32
+ if (classInfo[name]) {
33
+ result += `${name} `;
34
+ }
35
+ }
36
+ return result;
37
+ }
@@ -0,0 +1,5 @@
1
+ import { Block } from '@devvit/protos';
2
+ import { TemplateLike } from '@reddit/baseplate/html.js';
3
+ import { RenderContext } from './index.js';
4
+ export declare function renderAnimationBlock(block: Block, ctx: RenderContext): TemplateLike;
5
+ //# sourceMappingURL=renderAnimationBlock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderAnimationBlock.d.ts","sourceRoot":"","sources":["../../../src/blocks/templates/renderAnimationBlock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAEvC,OAAO,EAAW,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAIlE,OAAO,EAAY,aAAa,EAAE,MAAM,YAAY,CAAC;AAErD,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,aAAa,GAAG,YAAY,CA0BnF"}
@@ -0,0 +1,26 @@
1
+ import { nothing } from '@reddit/baseplate/html.js';
2
+ import { getTemplateRenderingStrategy } from '@reddit/faceplate-ui/faceplateUIConfig.js';
3
+ import { onClickAction, sizingClass, sizingStyle } from '../attributes.js';
4
+ import { classMap } from './index.js';
5
+ export function renderAnimationBlock(block, ctx) {
6
+ const { html, styleMap, ifDefined } = getTemplateRenderingStrategy();
7
+ if (!block.config?.animationConfig) {
8
+ console.error('Invalid block: Animation missing AnimationConfig');
9
+ return nothing;
10
+ }
11
+ const { url, type } = block.config.animationConfig;
12
+ const classes = {
13
+ ...sizingClass(block.size),
14
+ };
15
+ const styles = {
16
+ ...sizingStyle(block.size),
17
+ };
18
+ const onClick = onClickAction(block, ctx);
19
+ return html `<devvit-animation-player
20
+ class="${classMap(classes)}"
21
+ style="${styleMap(styles)}"
22
+ src="${url}"
23
+ type="${type}"
24
+ @click="${ifDefined(onClick)}"
25
+ ></devvit-animation-player>`;
26
+ }
@@ -0,0 +1,5 @@
1
+ import { Block } from '@devvit/protos';
2
+ import { TemplateLike } from '@reddit/baseplate/html.js';
3
+ import { RenderContext } from './index.js';
4
+ export declare function renderAvatarBlock(block: Block, ctx: RenderContext): TemplateLike;
5
+ //# sourceMappingURL=renderAvatarBlock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderAvatarBlock.d.ts","sourceRoot":"","sources":["../../../src/blocks/templates/renderAvatarBlock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAEvC,OAAO,EAAW,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAUlE,OAAO,EAAY,aAAa,EAAE,MAAM,YAAY,CAAC;AAErD,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,aAAa,GAAG,YAAY,CA0BhF"}
@@ -0,0 +1,26 @@
1
+ import { nothing } from '@reddit/baseplate/html.js';
2
+ import { getTemplateRenderingStrategy } from '@reddit/faceplate-ui/faceplateUIConfig.js';
3
+ import { avatarSizeClass, facingClass, onClickAction, sizingClass, sizingStyle, } from '../attributes.js';
4
+ import { classMap } from './index.js';
5
+ export function renderAvatarBlock(block, ctx) {
6
+ const { html, styleMap, ifDefined } = getTemplateRenderingStrategy();
7
+ if (!block.config?.avatarConfig) {
8
+ console.error('Invalid block: Avatar missing AvatarConfig');
9
+ return nothing;
10
+ }
11
+ const { thingId, facing, size, background } = block.config.avatarConfig;
12
+ const classes = {
13
+ ...sizingClass(block.size),
14
+ ...avatarSizeClass(size),
15
+ ...facingClass(facing),
16
+ };
17
+ const styles = {
18
+ ...sizingStyle(block.size),
19
+ };
20
+ const onClick = onClickAction(block, ctx);
21
+ return html `<div
22
+ class="${classMap(classes)}"
23
+ style="${styleMap(styles)}"
24
+ @click="${ifDefined(onClick)}"
25
+ ></div>`;
26
+ }
@@ -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 renderBlock(block: Block, ctx: RenderContext): TemplateLike;
5
+ //# sourceMappingURL=renderBlock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderBlock.d.ts","sourceRoot":"","sources":["../../../src/blocks/templates/renderBlock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAElE,OAAO,EAAE,KAAK,EAAa,MAAM,gBAAgB,CAAC;AAYlD,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,aAAa,GAAG,YAAY,CA0B1E"}
@@ -0,0 +1,39 @@
1
+ import { nothing } from '@reddit/baseplate/html.js';
2
+ import { BlockType } from '@devvit/protos';
3
+ import { renderStackBlock } from './renderStackBlock.js';
4
+ import { renderSpacerBlock } from './renderSpacerBlock.js';
5
+ import { renderTextBlock } from './renderTextBlock.js';
6
+ import { renderImageBlock } from './renderImageBlock.js';
7
+ import { renderIconBlock } from './renderIconBlock.js';
8
+ import { renderButtonBlock } from './renderButtonBlock.js';
9
+ import { renderWebViewBlock } from './renderWebViewBlock.js';
10
+ import { renderAnimationBlock } from './renderAnimationBlock.js';
11
+ import { renderAvatarBlock } from './renderAvatarBlock.js';
12
+ import { renderFullSnooBlock } from './renderFullSnooBlock.js';
13
+ export function renderBlock(block, ctx) {
14
+ switch (block.type) {
15
+ case BlockType.BLOCK_STACK:
16
+ return renderStackBlock(block, ctx);
17
+ case BlockType.BLOCK_SPACER:
18
+ return renderSpacerBlock(block, ctx);
19
+ case BlockType.BLOCK_TEXT:
20
+ return renderTextBlock(block, ctx);
21
+ case BlockType.BLOCK_IMAGE:
22
+ return renderImageBlock(block, ctx);
23
+ case BlockType.BLOCK_ICON:
24
+ return renderIconBlock(block, ctx);
25
+ case BlockType.BLOCK_BUTTON:
26
+ return renderButtonBlock(block, ctx);
27
+ case BlockType.BLOCK_WEBVIEW:
28
+ return renderWebViewBlock(block, ctx);
29
+ case BlockType.BLOCK_ANIMATION:
30
+ return renderAnimationBlock(block, ctx);
31
+ case BlockType.BLOCK_AVATAR:
32
+ return renderAvatarBlock(block, ctx);
33
+ case BlockType.BLOCK_FULLSNOO:
34
+ return renderFullSnooBlock(block, ctx);
35
+ case BlockType.UNRECOGNIZED:
36
+ default:
37
+ return nothing;
38
+ }
39
+ }
@@ -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 renderButtonBlock(block: Block, ctx: RenderContext): TemplateLike;
5
+ //# sourceMappingURL=renderButtonBlock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderButtonBlock.d.ts","sourceRoot":"","sources":["../../../src/blocks/templates/renderButtonBlock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAKzD,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AASvC,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,aAAa,GAAG,YAAY,CAyBhF"}
@@ -0,0 +1,26 @@
1
+ import { getTemplateRenderingStrategy } from '@reddit/faceplate-ui/faceplateUIConfig.js';
2
+ import { button } from '@reddit/faceplate-ui/templates/button.js';
3
+ import { styleMap } from '@reddit/faceplate-ui/templateUtils/styleMap.js';
4
+ import { backgroundStyle, buttonAppearance, buttonSize, colorStyle, onClickAction, } from '../attributes.js';
5
+ export function renderButtonBlock(block, ctx) {
6
+ const { html, ifDefined } = getTemplateRenderingStrategy();
7
+ // let buttonIcon = block.config?.buttonConfig?.icon;
8
+ const disabled = block.config?.buttonConfig?.disabled === true;
9
+ const styles = {
10
+ ...colorStyle(block.config?.buttonConfig?.textColor),
11
+ ...backgroundStyle(block.config?.buttonConfig?.backgroundColor),
12
+ };
13
+ const onClick = onClickAction(block, ctx);
14
+ return html `${button({
15
+ size: buttonSize(block.config?.buttonConfig?.buttonSize),
16
+ appearance: buttonAppearance(block.config?.buttonConfig?.buttonAppearance),
17
+ // leadingIcon: findIcon(buttonIcon),
18
+ children: ifDefined(block.config?.buttonConfig?.text),
19
+ attributes: {
20
+ disabled,
21
+ // convert from StyleInfo to CSSStyleDeclaration
22
+ style: styleMap(styles).string,
23
+ onclick: onClick ?? null,
24
+ },
25
+ })}`;
26
+ }
@@ -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 renderFullSnooBlock(block: Block, ctx: RenderContext): TemplateLike;
5
+ //# sourceMappingURL=renderFullSnooBlock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderFullSnooBlock.d.ts","sourceRoot":"","sources":["../../../src/blocks/templates/renderFullSnooBlock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGlE,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AASvC,OAAO,EAAY,aAAa,EAAE,MAAM,YAAY,CAAC;AAErD,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,aAAa,GAAG,YAAY,CA0BlF"}
@@ -0,0 +1,26 @@
1
+ import { nothing } from '@reddit/baseplate/html.js';
2
+ import { getTemplateRenderingStrategy } from '@reddit/faceplate-ui/faceplateUIConfig.js';
3
+ import { facingClass, fullSnooSizeClass, onClickAction, sizingClass, sizingStyle, } from '../attributes.js';
4
+ import { classMap } from './index.js';
5
+ export function renderFullSnooBlock(block, ctx) {
6
+ const { html, styleMap, ifDefined } = getTemplateRenderingStrategy();
7
+ if (!block.config?.fullsnooConfig) {
8
+ console.error('Invalid block: FullSnoo missing FullSnooConfig');
9
+ return nothing;
10
+ }
11
+ const { userId, size, facing } = block.config.fullsnooConfig;
12
+ const classes = {
13
+ ...sizingClass(block.size),
14
+ ...fullSnooSizeClass(size),
15
+ ...facingClass(facing),
16
+ };
17
+ const styles = {
18
+ ...sizingStyle(block.size),
19
+ };
20
+ const onClick = onClickAction(block, ctx);
21
+ return html `<div
22
+ class="${classMap(classes)}"
23
+ style="${styleMap(styles)}"
24
+ @click="${ifDefined(onClick)}"
25
+ ></div>`;
26
+ }
@@ -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 renderIconBlock(block: Block, ctx: RenderContext): TemplateLike;
5
+ //# sourceMappingURL=renderIconBlock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderIconBlock.d.ts","sourceRoot":"","sources":["../../../src/blocks/templates/renderIconBlock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGlE,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAGvC,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C,wBAAgB,eAAe,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,aAAa,GAAG,YAAY,CAmB9E"}
@@ -0,0 +1,17 @@
1
+ import { nothing } from '@reddit/baseplate/html.js';
2
+ import { getTemplateRenderingStrategy } from '@reddit/faceplate-ui/faceplateUIConfig.js';
3
+ import { iconSizeClass, onClickAction } from '../attributes.js';
4
+ export function renderIconBlock(block, ctx) {
5
+ const { html } = getTemplateRenderingStrategy();
6
+ if (!block.config?.iconConfig) {
7
+ console.error('Invalid block: Icon missing IconConfig');
8
+ return nothing;
9
+ }
10
+ const { icon, size, color } = block.config.iconConfig;
11
+ // adopt `icons-all.ts` from faceplate-ui storybook
12
+ const classes = {
13
+ ...iconSizeClass(size),
14
+ };
15
+ const onClick = onClickAction(block, ctx);
16
+ return html `<div></div>`;
17
+ }
@@ -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;AAGvC,OAAO,EAAY,aAAa,EAAE,MAAM,YAAY,CAAC;AAErD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,aAAa,GAAG,YAAY,CA+B/E"}