@devvit/ui-renderer 0.9.1 → 0.9.2

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 (65) hide show
  1. package/blocks/components/devvit-blocks-webview.d.ts +2 -0
  2. package/blocks/components/devvit-blocks-webview.d.ts.map +1 -0
  3. package/blocks/components/devvit-blocks-webview.js +81 -0
  4. package/blocks/templates/index.d.ts +3 -4
  5. package/blocks/templates/index.d.ts.map +1 -1
  6. package/blocks/templates/renderWebViewBlock.d.ts +1 -0
  7. package/blocks/templates/renderWebViewBlock.d.ts.map +1 -1
  8. package/blocks/templates/renderWebViewBlock.js +5 -15
  9. package/client/devvit-custom-post.d.ts +2 -2
  10. package/client/devvit-custom-post.d.ts.map +1 -1
  11. package/client/devvit-custom-post.js +22 -11
  12. package/client/effects/form-effect-handler.d.ts +1 -0
  13. package/client/effects/form-effect-handler.d.ts.map +1 -1
  14. package/client/effects/form-effect-handler.js +9 -5
  15. package/client/formbuilder/components/devvit-form-selection-dropdown.d.ts +17 -0
  16. package/client/formbuilder/components/devvit-form-selection-dropdown.d.ts.map +1 -0
  17. package/client/formbuilder/components/devvit-form-selection-dropdown.js +138 -0
  18. package/client/formbuilder/components/devvit-form-selection-list.d.ts +14 -0
  19. package/client/formbuilder/components/devvit-form-selection-list.d.ts.map +1 -0
  20. package/client/formbuilder/components/devvit-form-selection-list.js +91 -0
  21. package/client/formbuilder/devvit-form-dialog.d.ts +17 -0
  22. package/client/formbuilder/devvit-form-dialog.d.ts.map +1 -0
  23. package/client/formbuilder/devvit-form-dialog.js +152 -0
  24. package/client/formbuilder/fields/index.d.ts +12 -0
  25. package/client/formbuilder/fields/index.d.ts.map +1 -0
  26. package/client/formbuilder/fields/index.js +10 -0
  27. package/client/formbuilder/fields/renderBooleanField.d.ts +4 -0
  28. package/client/formbuilder/fields/renderBooleanField.d.ts.map +1 -0
  29. package/client/formbuilder/fields/renderBooleanField.js +14 -0
  30. package/client/formbuilder/fields/renderFieldLabel.d.ts +3 -0
  31. package/client/formbuilder/fields/renderFieldLabel.d.ts.map +1 -0
  32. package/client/formbuilder/fields/renderFieldLabel.js +3 -0
  33. package/client/formbuilder/fields/renderFormFields.d.ts +4 -0
  34. package/client/formbuilder/fields/renderFormFields.d.ts.map +1 -0
  35. package/client/formbuilder/fields/renderFormFields.js +18 -0
  36. package/client/formbuilder/fields/renderGroupField.d.ts +3 -0
  37. package/client/formbuilder/fields/renderGroupField.d.ts.map +1 -0
  38. package/client/formbuilder/fields/renderGroupField.js +13 -0
  39. package/client/formbuilder/fields/renderHelpText.d.ts +4 -0
  40. package/client/formbuilder/fields/renderHelpText.d.ts.map +1 -0
  41. package/client/formbuilder/fields/renderHelpText.js +3 -0
  42. package/client/formbuilder/fields/renderListField.d.ts +2 -0
  43. package/client/formbuilder/fields/renderListField.d.ts.map +1 -0
  44. package/client/formbuilder/fields/renderListField.js +1 -0
  45. package/client/formbuilder/fields/renderNumberField.d.ts +4 -0
  46. package/client/formbuilder/fields/renderNumberField.d.ts.map +1 -0
  47. package/client/formbuilder/fields/renderNumberField.js +23 -0
  48. package/client/formbuilder/fields/renderParagraphField.d.ts +5 -0
  49. package/client/formbuilder/fields/renderParagraphField.d.ts.map +1 -0
  50. package/client/formbuilder/fields/renderParagraphField.js +25 -0
  51. package/client/formbuilder/fields/renderSelectionField.d.ts +5 -0
  52. package/client/formbuilder/fields/renderSelectionField.d.ts.map +1 -0
  53. package/client/formbuilder/fields/renderSelectionField.js +18 -0
  54. package/client/formbuilder/fields/renderStringField.d.ts +4 -0
  55. package/client/formbuilder/fields/renderStringField.d.ts.map +1 -0
  56. package/client/formbuilder/fields/renderStringField.js +24 -0
  57. package/client/formbuilder/index.d.ts +2 -0
  58. package/client/formbuilder/index.d.ts.map +1 -0
  59. package/client/formbuilder/index.js +1 -0
  60. package/package.json +9 -8
  61. package/styles.css +15 -0
  62. package/styles.js +1 -1
  63. package/types/events.d.ts +20 -0
  64. package/types/events.d.ts.map +1 -0
  65. package/types/events.js +1 -0
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=devvit-blocks-webview.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"devvit-blocks-webview.d.ts","sourceRoot":"","sources":["../../../src/blocks/components/devvit-blocks-webview.ts"],"names":[],"mappings":""}
@@ -0,0 +1,81 @@
1
+ var _DevvitBlocksWebview_iframe, _DevvitBlocksWebview_handleMessage, _DevvitBlocksWebview_onLoad;
2
+ import { __classPrivateFieldGet, __decorate, __metadata } from "tslib";
3
+ import { css, html, LitElement } from 'lit';
4
+ import { customElement, property } from 'lit/decorators.js';
5
+ import { createRef, ref } from 'lit/directives/ref.js';
6
+ import { ifDefined } from '@reddit/baseplate/html.js';
7
+ import { customEvent } from '@reddit/faceplate/lib/custom-event.js';
8
+ import { BlockActionType } from '@devvit/protos';
9
+ /**
10
+ * Wraps an iframe to capture messages sent from within to be handled by the app rendering the Blocks
11
+ */
12
+ let DevvitBlocksWebview = class DevvitBlocksWebview extends LitElement {
13
+ constructor() {
14
+ super(...arguments);
15
+ _DevvitBlocksWebview_iframe.set(this, createRef());
16
+ _DevvitBlocksWebview_handleMessage.set(this, (event) => {
17
+ if (event.source === __classPrivateFieldGet(this, _DevvitBlocksWebview_iframe, "f").value?.contentWindow) {
18
+ event.stopImmediatePropagation();
19
+ const action = {
20
+ type: BlockActionType.ACTION_WEBVIEW,
21
+ id: event.data.id,
22
+ data: event.data.data,
23
+ };
24
+ this.dispatchEvent(customEvent('devvit-user-action', { action }));
25
+ }
26
+ });
27
+ _DevvitBlocksWebview_onLoad.set(this, () => {
28
+ __classPrivateFieldGet(this, _DevvitBlocksWebview_iframe, "f")?.value?.contentWindow?.postMessage({
29
+ event: this.request,
30
+ state: this.state,
31
+ }, '*');
32
+ });
33
+ }
34
+ static get styles() {
35
+ return [
36
+ css `
37
+ :host {
38
+ display: flex;
39
+ flex-direction: row;
40
+ }
41
+
42
+ iframe {
43
+ flex-grow: 1;
44
+ border: 0;
45
+ }
46
+ `,
47
+ ];
48
+ }
49
+ connectedCallback() {
50
+ super.connectedCallback();
51
+ window.addEventListener('message', __classPrivateFieldGet(this, _DevvitBlocksWebview_handleMessage, "f"));
52
+ }
53
+ disconnectedCallback() {
54
+ super.disconnectedCallback();
55
+ window.removeEventListener('message', __classPrivateFieldGet(this, _DevvitBlocksWebview_handleMessage, "f"));
56
+ }
57
+ render() {
58
+ return html `<iframe
59
+ src="${ifDefined(this.src)}"
60
+ sandbox="allow-scripts"
61
+ @load="${__classPrivateFieldGet(this, _DevvitBlocksWebview_onLoad, "f")}"
62
+ ${ref(__classPrivateFieldGet(this, _DevvitBlocksWebview_iframe, "f"))}
63
+ ></iframe>`;
64
+ }
65
+ };
66
+ _DevvitBlocksWebview_iframe = new WeakMap(), _DevvitBlocksWebview_handleMessage = new WeakMap(), _DevvitBlocksWebview_onLoad = new WeakMap();
67
+ __decorate([
68
+ property({ type: String }),
69
+ __metadata("design:type", Object)
70
+ ], DevvitBlocksWebview.prototype, "src", void 0);
71
+ __decorate([
72
+ property({ attribute: false }),
73
+ __metadata("design:type", Object)
74
+ ], DevvitBlocksWebview.prototype, "request", void 0);
75
+ __decorate([
76
+ property({ attribute: false }),
77
+ __metadata("design:type", Object)
78
+ ], DevvitBlocksWebview.prototype, "state", void 0);
79
+ DevvitBlocksWebview = __decorate([
80
+ customElement('devvit-blocks-webview')
81
+ ], DevvitBlocksWebview);
@@ -1,9 +1,8 @@
1
- import { classMap as clientClassMap } from 'lit/directives/class-map.js';
1
+ import { ClassInfo, classMap as clientClassMap } from 'lit/directives/class-map.js';
2
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';
3
+ import { Block, BlockAction, BlockRenderRequest, BlockStackDirection } from '@devvit/protos';
5
4
  export interface RenderContext {
6
- blockRender?: BlockRenderResponse | undefined;
5
+ request?: BlockRenderRequest | undefined;
7
6
  state?: unknown | undefined;
8
7
  stackDirection: BlockStackDirection;
9
8
  onAction?: ((action: BlockAction) => void) | undefined;
@@ -1 +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,EAAU,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAExF,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,CACtB,SAAS,EAAE,SAAS,EACpB,WAAW,CAAC,EAAE,OAAO,GACpB,YAAY,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAgBlD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/blocks/templates/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,IAAI,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAEpF,OAAO,EAAW,YAAY,EAAU,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAExF,OAAO,EACL,KAAK,EACL,WAAW,EACX,kBAAkB,EAClB,mBAAmB,EAEpB,MAAM,gBAAgB,CAAC;AAKxB,MAAM,WAAW,aAAa;IAC5B,OAAO,CAAC,EAAE,kBAAkB,GAAG,SAAS,CAAC;IACzC,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,CACtB,SAAS,EAAE,SAAS,EACpB,WAAW,CAAC,EAAE,OAAO,GACpB,YAAY,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAgBlD"}
@@ -1,5 +1,6 @@
1
1
  import { TemplateLike } from '@reddit/baseplate/html.js';
2
2
  import { Block } from '@devvit/protos';
3
3
  import { RenderContext } from './index.js';
4
+ import '../components/devvit-blocks-webview.js';
4
5
  export declare function renderWebViewBlock(block: Block, ctx: RenderContext): TemplateLike;
5
6
  //# sourceMappingURL=renderWebViewBlock.d.ts.map
@@ -1 +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"}
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;AAErD,OAAO,wCAAwC,CAAC;AAEhD,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,aAAa,GAAG,YAAY,CA2BjF"}
@@ -2,11 +2,7 @@ import { nothing } from '@reddit/baseplate/html.js';
2
2
  import { getTemplateRenderingStrategy } from '@reddit/faceplate-ui/faceplateUIConfig.js';
3
3
  import { defaultClasses, sizingClass, sizingStyle, stackChildClass } from '../attributes.js';
4
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
- };
5
+ import '../components/devvit-blocks-webview.js';
10
6
  export function renderWebViewBlock(block, ctx) {
11
7
  const { html, styleMap } = getTemplateRenderingStrategy();
12
8
  if (!block.config?.webviewConfig) {
@@ -22,18 +18,12 @@ export function renderWebViewBlock(block, ctx) {
22
18
  const styles = {
23
19
  ...sizingStyle(block.size),
24
20
  };
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
21
+ return html `<devvit-blocks-webview
31
22
  src="${url}"
32
- sandbox="allow-scripts"
33
23
  class="${classMap(classes)}"
34
24
  style="${styleMap(styles)}"
35
- @load="${onLoad}"
36
- ref="${saveRef}"
25
+ .request="${ctx.request}"
26
+ .state="${ctx.state}"
37
27
  data-debug-block-type="webview"
38
- ></iframe>`;
28
+ ></devvit-blocks-webview>`;
39
29
  }
@@ -1,6 +1,6 @@
1
1
  import { LitElement, PropertyValues } from 'lit';
2
2
  import '@reddit/faceplate-ui/templateRenderingStrategy/clientStrategy.js';
3
- import type { Element, Metadata } from '@devvit/protos';
3
+ import type { Metadata } from '@devvit/protos';
4
4
  import { Block, RenderPostResponse } from '@devvit/protos';
5
5
  import type { ActorRef } from '@devvit/runtimes/common/runtime/ActorRef.js';
6
6
  import './devvit-animation-player.js';
@@ -16,8 +16,8 @@ export declare class DevvitCustomPost extends LitElement {
16
16
  postId?: string;
17
17
  renderResponse?: RenderPostResponse;
18
18
  rootBlock?: Block;
19
- alphaRootBlock?: Element;
20
19
  static get styles(): import("lit").CSSResult[];
20
+ connectedCallback(): void;
21
21
  disconnectedCallback(): void;
22
22
  protected willUpdate(changedProperties: PropertyValues): void;
23
23
  render(): import("@reddit/baseplate/html.js").TemplateLike;
@@ -1 +1 @@
1
- {"version":3,"file":"devvit-custom-post.d.ts","sourceRoot":"","sources":["../../src/client/devvit-custom-post.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,UAAU,EAAE,cAAc,EAAE,MAAM,KAAK,CAAC;AAIvD,OAAO,kEAAkE,CAAC;AAK1E,OAAO,KAAK,EAIV,OAAO,EAEP,QAAQ,EAIT,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,KAAK,EAML,kBAAkB,EAEnB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,6CAA6C,CAAC;AAK5E,OAAO,8BAA8B,CAAC;AAEtC,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,oBAAoB,EAAE,gBAAgB,CAAC;KACxC;CACF;AASD,qBACa,gBAAiB,SAAQ,UAAU;;IAE9C,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAGpB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAGpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAGhB,cAAc,CAAC,EAAE,kBAAkB,CAAC;IAGpC,SAAS,CAAC,EAAE,KAAK,CAAC;IAGlB,cAAc,CAAC,EAAE,OAAO,CAAC;IAYzB,WAAoB,MAAM,8BAEzB;IAMQ,oBAAoB;cAOV,UAAU,CAAC,iBAAiB,EAAE,cAAc;IAatD,MAAM;CA6FhB"}
1
+ {"version":3,"file":"devvit-custom-post.d.ts","sourceRoot":"","sources":["../../src/client/devvit-custom-post.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,UAAU,EAAE,cAAc,EAAE,MAAM,KAAK,CAAC;AAKvD,OAAO,kEAAkE,CAAC;AAI1E,OAAO,KAAK,EAMV,QAAQ,EAIT,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,KAAK,EAML,kBAAkB,EAEnB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,6CAA6C,CAAC;AAM5E,OAAO,8BAA8B,CAAC;AAEtC,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,oBAAoB,EAAE,gBAAgB,CAAC;KACxC;CACF;AASD,qBAEa,gBAAiB,SAAQ,UAAU;;IAE9C,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAGpB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAGpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAGhB,cAAc,CAAC,EAAE,kBAAkB,CAAC;IAGpC,SAAS,CAAC,EAAE,KAAK,CAAC;IAalB,WAAoB,MAAM,8BAEzB;IAMQ,iBAAiB;IAKjB,oBAAoB;cAQV,UAAU,CAAC,iBAAiB,EAAE,cAAc;IAatD,MAAM;CAqGhB"}
@@ -1,15 +1,16 @@
1
- var _DevvitCustomPost_instances, _DevvitCustomPost_postData, _DevvitCustomPost_appState, _DevvitCustomPost_customPostActor, _DevvitCustomPost_uiEventHandlerActor, _DevvitCustomPost_rpcQueue, _DevvitCustomPost_rerenderTimeout, _DevvitCustomPost_state_get, _DevvitCustomPost_handleUIEvent, _DevvitCustomPost_renderRequest, _DevvitCustomPost_initialRender, _DevvitCustomPost_userActionRender, _DevvitCustomPost_effectEventRender, _DevvitCustomPost_renderPost, _DevvitCustomPost_handleEffects;
1
+ var _DevvitCustomPost_instances, _DevvitCustomPost_postData, _DevvitCustomPost_appState, _DevvitCustomPost_lastRequest, _DevvitCustomPost_customPostActor, _DevvitCustomPost_uiEventHandlerActor, _DevvitCustomPost_rpcQueue, _DevvitCustomPost_rerenderTimeout, _DevvitCustomPost_state_get, _DevvitCustomPost_handleUIEvent, _DevvitCustomPost_handleUserAction, _DevvitCustomPost_renderRequest, _DevvitCustomPost_initialRender, _DevvitCustomPost_userActionRender, _DevvitCustomPost_effectEventRender, _DevvitCustomPost_renderPost, _DevvitCustomPost_handleEffects;
2
2
  import { __classPrivateFieldGet, __classPrivateFieldSet, __decorate, __metadata } from "tslib";
3
3
  import { html, LitElement } from 'lit';
4
4
  import { customElement, property, state } from 'lit/decorators.js';
5
+ import { localized, msg } from '@lit/localize';
5
6
  import PQueue from 'p-queue';
6
7
  import '@reddit/faceplate-ui/templateRenderingStrategy/clientStrategy.js';
7
8
  import { emptyState } from '@reddit/faceplate-ui/templates/empty-state.js';
8
9
  import { customEvent } from '@reddit/faceplate/lib/custom-event.js';
9
- import { styles } from '../styles.js';
10
10
  import { Block, BlockRenderEventType, BlockStackDirection, BlockType, CustomPostDefinition, EffectType, RenderPostResponse, UIEventHandlerDefinition, } from '@devvit/protos';
11
11
  import { renderBlocks } from '../blocks/index.js';
12
12
  import { snooBlocks } from './assets/snooBlocks.js';
13
+ import { styles } from '../styles.js';
13
14
  import './devvit-animation-player.js';
14
15
  let DevvitCustomPost = class DevvitCustomPost extends LitElement {
15
16
  constructor() {
@@ -17,6 +18,7 @@ let DevvitCustomPost = class DevvitCustomPost extends LitElement {
17
18
  _DevvitCustomPost_instances.add(this);
18
19
  _DevvitCustomPost_postData.set(this, void 0);
19
20
  _DevvitCustomPost_appState.set(this, {});
21
+ _DevvitCustomPost_lastRequest.set(this, void 0);
20
22
  _DevvitCustomPost_customPostActor.set(this, void 0);
21
23
  _DevvitCustomPost_uiEventHandlerActor.set(this, void 0);
22
24
  _DevvitCustomPost_rpcQueue.set(this, new PQueue({ concurrency: 1 }));
@@ -35,6 +37,9 @@ let DevvitCustomPost = class DevvitCustomPost extends LitElement {
35
37
  }
36
38
  });
37
39
  });
40
+ _DevvitCustomPost_handleUserAction.set(this, (event) => {
41
+ __classPrivateFieldGet(this, _DevvitCustomPost_instances, "m", _DevvitCustomPost_userActionRender).call(this, event.detail.action.id, event.detail.action.data);
42
+ });
38
43
  _DevvitCustomPost_renderRequest.set(this, (type, id, data = {}) => ({
39
44
  blocks: { type, id, data },
40
45
  state: __classPrivateFieldGet(this, _DevvitCustomPost_instances, "a", _DevvitCustomPost_state_get),
@@ -43,11 +48,16 @@ let DevvitCustomPost = class DevvitCustomPost extends LitElement {
43
48
  static get styles() {
44
49
  return [styles];
45
50
  }
51
+ connectedCallback() {
52
+ super.connectedCallback();
53
+ this.addEventListener('devvit-user-action', __classPrivateFieldGet(this, _DevvitCustomPost_handleUserAction, "f"));
54
+ }
46
55
  disconnectedCallback() {
47
56
  super.disconnectedCallback();
48
57
  if (__classPrivateFieldGet(this, _DevvitCustomPost_rerenderTimeout, "f") !== undefined) {
49
58
  window.clearTimeout(__classPrivateFieldGet(this, _DevvitCustomPost_rerenderTimeout, "f"));
50
59
  }
60
+ this.removeEventListener('devvit-user-action', __classPrivateFieldGet(this, _DevvitCustomPost_handleUserAction, "f"));
51
61
  }
52
62
  willUpdate(changedProperties) {
53
63
  if (changedProperties.has('actorRef')) {
@@ -65,7 +75,7 @@ let DevvitCustomPost = class DevvitCustomPost extends LitElement {
65
75
  }
66
76
  if (this.rootBlock && this.rootBlock.type === BlockType.BLOCK_ROOT) {
67
77
  return renderBlocks(this.rootBlock, {
68
- blockRender: this.renderResponse.blocks,
78
+ request: __classPrivateFieldGet(this, _DevvitCustomPost_lastRequest, "f"),
69
79
  state: __classPrivateFieldGet(this, _DevvitCustomPost_instances, "a", _DevvitCustomPost_state_get),
70
80
  stackDirection: BlockStackDirection.UNRECOGNIZED,
71
81
  onAction: (action) => {
@@ -74,13 +84,15 @@ let DevvitCustomPost = class DevvitCustomPost extends LitElement {
74
84
  });
75
85
  }
76
86
  return html `${emptyState({
77
- creative: html `<div class="w-lg h-lg">${snooBlocks}</div>`,
78
- title: 'Whoops!',
79
- description: 'Something went wrong while attempting to display this content.',
87
+ creative: html `<div class="w-3xl h-3xl">${snooBlocks}</div>`,
88
+ title: msg('Whoops!', { desc: 'Header for message to display when rendering fails' }),
89
+ description: msg('Something went wrong while attempting to display this content.', {
90
+ desc: 'Message for users to display when rendering fails',
91
+ }),
80
92
  })}`;
81
93
  }
82
94
  };
83
- _DevvitCustomPost_postData = new WeakMap(), _DevvitCustomPost_appState = new WeakMap(), _DevvitCustomPost_customPostActor = new WeakMap(), _DevvitCustomPost_uiEventHandlerActor = new WeakMap(), _DevvitCustomPost_rpcQueue = new WeakMap(), _DevvitCustomPost_rerenderTimeout = new WeakMap(), _DevvitCustomPost_handleUIEvent = new WeakMap(), _DevvitCustomPost_renderRequest = new WeakMap(), _DevvitCustomPost_instances = new WeakSet(), _DevvitCustomPost_state_get = function _DevvitCustomPost_state_get() {
95
+ _DevvitCustomPost_postData = new WeakMap(), _DevvitCustomPost_appState = new WeakMap(), _DevvitCustomPost_lastRequest = new WeakMap(), _DevvitCustomPost_customPostActor = new WeakMap(), _DevvitCustomPost_uiEventHandlerActor = new WeakMap(), _DevvitCustomPost_rpcQueue = new WeakMap(), _DevvitCustomPost_rerenderTimeout = new WeakMap(), _DevvitCustomPost_handleUIEvent = new WeakMap(), _DevvitCustomPost_handleUserAction = new WeakMap(), _DevvitCustomPost_renderRequest = new WeakMap(), _DevvitCustomPost_instances = new WeakSet(), _DevvitCustomPost_state_get = function _DevvitCustomPost_state_get() {
84
96
  return Object.assign({}, __classPrivateFieldGet(this, _DevvitCustomPost_postData, "f"), __classPrivateFieldGet(this, _DevvitCustomPost_appState, "f"));
85
97
  }, _DevvitCustomPost_initialRender = function _DevvitCustomPost_initialRender() {
86
98
  __classPrivateFieldGet(this, _DevvitCustomPost_instances, "m", _DevvitCustomPost_renderPost).call(this, __classPrivateFieldGet(this, _DevvitCustomPost_renderRequest, "f").call(this, BlockRenderEventType.RENDER_INITIAL));
@@ -97,7 +109,9 @@ _DevvitCustomPost_postData = new WeakMap(), _DevvitCustomPost_appState = new Wea
97
109
  __classPrivateFieldSet(this, _DevvitCustomPost_appState, this.renderResponse.state, "f");
98
110
  }
99
111
  if (this.renderResponse?.blocks?.ui) {
112
+ __classPrivateFieldSet(this, _DevvitCustomPost_lastRequest, req.blocks, "f");
100
113
  this.rootBlock = this.renderResponse.blocks.ui;
114
+ await this.updateComplete;
101
115
  }
102
116
  await __classPrivateFieldGet(this, _DevvitCustomPost_instances, "m", _DevvitCustomPost_handleEffects).call(this, this.renderResponse.effects);
103
117
  }
@@ -137,11 +151,8 @@ __decorate([
137
151
  state(),
138
152
  __metadata("design:type", Object)
139
153
  ], DevvitCustomPost.prototype, "rootBlock", void 0);
140
- __decorate([
141
- state(),
142
- __metadata("design:type", Object)
143
- ], DevvitCustomPost.prototype, "alphaRootBlock", void 0);
144
154
  DevvitCustomPost = __decorate([
155
+ localized(),
145
156
  customElement('devvit-custom-post')
146
157
  ], DevvitCustomPost);
147
158
  export { DevvitCustomPost };
@@ -4,6 +4,7 @@ import { ReactiveElement } from 'lit';
4
4
  export declare class FormEffectHandler extends DevvitEffectHandler {
5
5
  #private;
6
6
  constructor(host: ReactiveElement, queryString: string);
7
+ hostUpdated(): void;
7
8
  protected onShowForm(form: Form, onEvent: (event: UIEvent) => void): void;
8
9
  }
9
10
  //# sourceMappingURL=form-effect-handler.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"form-effect-handler.d.ts","sourceRoot":"","sources":["../../../src/client/effects/form-effect-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,KAAK,CAAC;AAGtC,qBAAa,iBAAkB,SAAQ,mBAAmB;;gBAG5C,IAAI,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM;cAKnC,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI;CAG5E"}
1
+ {"version":3,"file":"form-effect-handler.d.ts","sourceRoot":"","sources":["../../../src/client/effects/form-effect-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,KAAK,CAAC;AAGtC,qBAAa,iBAAkB,SAAQ,mBAAmB;;gBAK5C,IAAI,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM;IAK7C,WAAW;cAKD,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI;CAG5E"}
@@ -1,15 +1,19 @@
1
- var _FormEffectHandler_queryString;
2
- import { __classPrivateFieldSet } from "tslib";
1
+ var _FormEffectHandler_queryString, _FormEffectHandler_dialog;
2
+ import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
3
3
  import { DevvitEffectHandler } from './devvit-effect-handler.js';
4
- import { customEvent } from '@reddit/faceplate/lib/custom-event.js';
5
4
  export class FormEffectHandler extends DevvitEffectHandler {
6
5
  constructor(host, queryString) {
7
6
  super(host);
8
7
  _FormEffectHandler_queryString.set(this, void 0);
8
+ _FormEffectHandler_dialog.set(this, void 0);
9
9
  __classPrivateFieldSet(this, _FormEffectHandler_queryString, queryString, "f");
10
10
  }
11
+ hostUpdated() {
12
+ super.hostUpdated();
13
+ __classPrivateFieldSet(this, _FormEffectHandler_dialog, this.host.renderRoot.querySelector(__classPrivateFieldGet(this, _FormEffectHandler_queryString, "f")), "f");
14
+ }
11
15
  onShowForm(form, onEvent) {
12
- this.host.dispatchEvent(customEvent('devvit-show-form', { form, onEvent }));
16
+ __classPrivateFieldGet(this, _FormEffectHandler_dialog, "f")?.showForm(form, onEvent);
13
17
  }
14
18
  }
15
- _FormEffectHandler_queryString = new WeakMap();
19
+ _FormEffectHandler_queryString = new WeakMap(), _FormEffectHandler_dialog = new WeakMap();
@@ -0,0 +1,17 @@
1
+ import { PropertyValues, TemplateResult } from 'lit';
2
+ import { FormField } from '@devvit/protos';
3
+ import '@reddit/faceplate-ui/components/faceplate-dropdown-menu.js';
4
+ import '@reddit/faceplate-ui/components/faceplate-menu.js';
5
+ import '@reddit/faceplate-ui/components/faceplate-switch-input.js';
6
+ import { InputElement } from '@reddit/faceplate/base-classes/input-element.js';
7
+ export declare class DevvitFormSelectionDropdown extends InputElement {
8
+ #private;
9
+ field: FormField | undefined;
10
+ dropdownOpen: boolean;
11
+ currentLabel: string;
12
+ static get styles(): import("lit").CSSResultGroup[];
13
+ get value(): string;
14
+ willUpdate(changedProperties: PropertyValues): void;
15
+ render(): TemplateResult<1>;
16
+ }
17
+ //# sourceMappingURL=devvit-form-selection-dropdown.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"devvit-form-selection-dropdown.d.ts","sourceRoot":"","sources":["../../../../src/client/formbuilder/components/devvit-form-selection-dropdown.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,cAAc,EAAE,cAAc,EAAE,MAAM,KAAK,CAAC;AASjE,OAAO,EAGL,SAAS,EAEV,MAAM,gBAAgB,CAAC;AAIxB,OAAO,4DAA4D,CAAC;AACpE,OAAO,mDAAmD,CAAC;AAC3D,OAAO,2DAA2D,CAAC;AAEnE,OAAO,EAAE,YAAY,EAAE,MAAM,iDAAiD,CAAC;AAE/E,qBAAa,2BAA4B,SAAQ,YAAY;;IAE3D,KAAK,EAAE,SAAS,GAAG,SAAS,CAAC;IAG7B,YAAY,UAAS;IAGrB,YAAY,SAAM;IAKlB,WAAoB,MAAM,mCAEzB;IAED,IAAI,KAAK,WAER;IAED,UAAU,CAAC,iBAAiB,EAAE,cAAc;IAwDnC,MAAM,IAAI,cAAc,CAAC,CAAC,CAAC;CAgDrC"}
@@ -0,0 +1,138 @@
1
+ var _DevvitFormSelectionDropdown_selection, _DevvitFormSelectionDropdown_config, _DevvitFormSelectionDropdown_updateSelection, _DevvitFormSelectionDropdown_singleSelectListItem, _DevvitFormSelectionDropdown_multiSelectListItem;
2
+ import { __classPrivateFieldGet, __classPrivateFieldSet, __decorate, __metadata } from "tslib";
3
+ import { property, state } from 'lit/decorators.js';
4
+ import { html, ifDefined } from '@reddit/faceplate-ui/templateRenderingStrategy/clientStrategy.js';
5
+ import { listItem } from '@reddit/faceplate-ui/templates/list-item.js';
6
+ import { button } from '@reddit/faceplate-ui/templates/button.js';
7
+ import { msg } from '@reddit/faceplate/lib/i18n/localize.js';
8
+ import { FieldConfig_Selection, FormFieldValue_SelectionValue, } from '@devvit/protos';
9
+ import { styles } from '../../../styles.js';
10
+ import '@reddit/faceplate-ui/components/faceplate-dropdown-menu.js';
11
+ import '@reddit/faceplate-ui/components/faceplate-menu.js';
12
+ import '@reddit/faceplate-ui/components/faceplate-switch-input.js';
13
+ import { classMap } from 'lit/directives/class-map.js';
14
+ import { InputElement } from '@reddit/faceplate/base-classes/input-element.js';
15
+ export class DevvitFormSelectionDropdown extends InputElement {
16
+ constructor() {
17
+ super(...arguments);
18
+ this.dropdownOpen = false;
19
+ this.currentLabel = '';
20
+ _DevvitFormSelectionDropdown_selection.set(this, FormFieldValue_SelectionValue.fromPartial({}));
21
+ _DevvitFormSelectionDropdown_config.set(this, FieldConfig_Selection.fromPartial({}));
22
+ _DevvitFormSelectionDropdown_updateSelection.set(this, (choice, selected = true) => {
23
+ if (__classPrivateFieldGet(this, _DevvitFormSelectionDropdown_config, "f").multiSelect) {
24
+ const index = __classPrivateFieldGet(this, _DevvitFormSelectionDropdown_selection, "f").values.indexOf(choice.value);
25
+ if (selected && index < 0) {
26
+ __classPrivateFieldGet(this, _DevvitFormSelectionDropdown_selection, "f").values.push(choice.value);
27
+ }
28
+ else if (index >= 0) {
29
+ __classPrivateFieldGet(this, _DevvitFormSelectionDropdown_selection, "f").values.splice(index, 1);
30
+ }
31
+ if (__classPrivateFieldGet(this, _DevvitFormSelectionDropdown_selection, "f").values.length === 0) {
32
+ this.currentLabel = '';
33
+ }
34
+ else if (__classPrivateFieldGet(this, _DevvitFormSelectionDropdown_selection, "f").values.length === 1) {
35
+ this.currentLabel =
36
+ __classPrivateFieldGet(this, _DevvitFormSelectionDropdown_config, "f").choices.find((c) => c.value === __classPrivateFieldGet(this, _DevvitFormSelectionDropdown_selection, "f").values[0])?.label ?? '';
37
+ }
38
+ else {
39
+ this.currentLabel = msg('[Multiple Selections]', {
40
+ desc: 'Displayed on a drop down menu when multiple values are selected',
41
+ });
42
+ }
43
+ }
44
+ else {
45
+ __classPrivateFieldGet(this, _DevvitFormSelectionDropdown_selection, "f").values = [choice.value];
46
+ this.currentLabel = choice.label;
47
+ }
48
+ });
49
+ _DevvitFormSelectionDropdown_singleSelectListItem.set(this, (choice) => listItem({
50
+ label: choice.label,
51
+ onClick: () => __classPrivateFieldGet(this, _DevvitFormSelectionDropdown_updateSelection, "f").call(this, choice),
52
+ }));
53
+ _DevvitFormSelectionDropdown_multiSelectListItem.set(this, (choice) => listItem({
54
+ label: html `
55
+ <faceplate-switch-input
56
+ @input="${(ev) => __classPrivateFieldGet(this, _DevvitFormSelectionDropdown_updateSelection, "f").call(this, choice, ev.currentTarget.checked)}"
57
+ >
58
+ ${choice.label}
59
+ </faceplate-switch-input>
60
+ `,
61
+ onClick: (ev) => ev.stopImmediatePropagation(),
62
+ }));
63
+ }
64
+ static get styles() {
65
+ return [super.styles, styles];
66
+ }
67
+ get value() {
68
+ return __classPrivateFieldGet(this, _DevvitFormSelectionDropdown_selection, "f").values.join(',');
69
+ }
70
+ willUpdate(changedProperties) {
71
+ if (changedProperties.has('field')) {
72
+ __classPrivateFieldSet(this, _DevvitFormSelectionDropdown_config, this.field?.fieldConfig?.selectionConfig ?? FieldConfig_Selection.fromPartial({}), "f");
73
+ __classPrivateFieldSet(this, _DevvitFormSelectionDropdown_selection, this.field?.defaultValue?.selectionValue ?? FormFieldValue_SelectionValue.fromPartial({}), "f");
74
+ if (!__classPrivateFieldGet(this, _DevvitFormSelectionDropdown_config, "f").multiSelect) {
75
+ this.currentLabel =
76
+ __classPrivateFieldGet(this, _DevvitFormSelectionDropdown_config, "f").choices.find((c) => c.value === __classPrivateFieldGet(this, _DevvitFormSelectionDropdown_selection, "f").values?.[0])?.label ?? '';
77
+ }
78
+ }
79
+ }
80
+ render() {
81
+ let formField;
82
+ if (this.field) {
83
+ const items = __classPrivateFieldGet(this, _DevvitFormSelectionDropdown_config, "f").choices?.map((choice) => __classPrivateFieldGet(this, _DevvitFormSelectionDropdown_config, "f").multiSelect
84
+ ? __classPrivateFieldGet(this, _DevvitFormSelectionDropdown_multiSelectListItem, "f").call(this, choice)
85
+ : __classPrivateFieldGet(this, _DevvitFormSelectionDropdown_singleSelectListItem, "f").call(this, choice));
86
+ const emptyItem = !__classPrivateFieldGet(this, _DevvitFormSelectionDropdown_config, "f").multiSelect && !__classPrivateFieldGet(this, _DevvitFormSelectionDropdown_config, "f").minSelections
87
+ ? listItem({
88
+ label: html `&nbsp;`,
89
+ onClick: () => {
90
+ this.currentLabel = '';
91
+ __classPrivateFieldGet(this, _DevvitFormSelectionDropdown_selection, "f").values = [];
92
+ },
93
+ })
94
+ : undefined;
95
+ const classes = {
96
+ 'flex-grow': true,
97
+ 'z-auto': !this.dropdownOpen,
98
+ };
99
+ formField = html `
100
+ <faceplate-dropdown-menu
101
+ id="${this.field.fieldId}"
102
+ class="${classMap(classes)}"
103
+ .onopen="${() => (this.dropdownOpen = true)}"
104
+ .onclose="${() => (this.dropdownOpen = false)}"
105
+ ?disabled="${ifDefined(this.field.disabled)}"
106
+ >
107
+ ${button({
108
+ attributes: {
109
+ disabled: this.field.disabled === true,
110
+ className: 'flex-grow',
111
+ },
112
+ children: html `<span class="grow">${this.currentLabel}</span>`,
113
+ selected: this.dropdownOpen,
114
+ dropdown: true,
115
+ })}
116
+ <faceplate-menu slot="menu">${emptyItem}${items}</faceplate-menu>
117
+ </faceplate-dropdown-menu>
118
+ `;
119
+ }
120
+ return html `${formField}${super.render()}`;
121
+ }
122
+ }
123
+ _DevvitFormSelectionDropdown_selection = new WeakMap(), _DevvitFormSelectionDropdown_config = new WeakMap(), _DevvitFormSelectionDropdown_updateSelection = new WeakMap(), _DevvitFormSelectionDropdown_singleSelectListItem = new WeakMap(), _DevvitFormSelectionDropdown_multiSelectListItem = new WeakMap();
124
+ __decorate([
125
+ property({ attribute: false }),
126
+ __metadata("design:type", Object)
127
+ ], DevvitFormSelectionDropdown.prototype, "field", void 0);
128
+ __decorate([
129
+ state(),
130
+ __metadata("design:type", Object)
131
+ ], DevvitFormSelectionDropdown.prototype, "dropdownOpen", void 0);
132
+ __decorate([
133
+ state(),
134
+ __metadata("design:type", Object)
135
+ ], DevvitFormSelectionDropdown.prototype, "currentLabel", void 0);
136
+ // Faceplate's base classes and mixins aren't playing nice with type checking for some reason
137
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
138
+ customElements.define('devvit-form-selection-dropdown', DevvitFormSelectionDropdown);
@@ -0,0 +1,14 @@
1
+ import { PropertyValues, TemplateResult } from 'lit';
2
+ import { FormField } from '@devvit/protos';
3
+ import '@reddit/faceplate-ui/components/faceplate-radio-input.js';
4
+ import '@reddit/faceplate-ui/components/faceplate-checkbox-input.js';
5
+ import { InputElement } from '@reddit/faceplate/base-classes/input-element.js';
6
+ export declare class DevvitFormSelectionList extends InputElement {
7
+ #private;
8
+ field: FormField | undefined;
9
+ static get styles(): import("lit").CSSResultGroup[];
10
+ get value(): string;
11
+ willUpdate(changedProperties: PropertyValues): void;
12
+ render(): TemplateResult<1>;
13
+ }
14
+ //# sourceMappingURL=devvit-form-selection-list.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"devvit-form-selection-list.d.ts","sourceRoot":"","sources":["../../../../src/client/formbuilder/components/devvit-form-selection-list.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,cAAc,EAAE,cAAc,EAAE,MAAM,KAAK,CAAC;AAMjE,OAAO,EAGL,SAAS,EAEV,MAAM,gBAAgB,CAAC;AAKxB,OAAO,0DAA0D,CAAC;AAClE,OAAO,6DAA6D,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,iDAAiD,CAAC;AAE/E,qBAAa,uBAAwB,SAAQ,YAAY;;IAEvD,KAAK,EAAE,SAAS,GAAG,SAAS,CAAC;IAK7B,WAAoB,MAAM,mCAEzB;IAED,IAAI,KAAK,WAER;IAED,UAAU,CAAC,iBAAiB,EAAE,cAAc;IAsBnC,MAAM,IAAI,cAAc,CAAC,CAAC,CAAC;CA6CrC"}
@@ -0,0 +1,91 @@
1
+ var _DevvitFormSelectionList_config, _DevvitFormSelectionList_selection, _DevvitFormSelectionList_updateSelection;
2
+ import { __classPrivateFieldGet, __classPrivateFieldSet, __decorate, __metadata } from "tslib";
3
+ import { property } from 'lit/decorators.js';
4
+ import { html, repeat } from '@reddit/faceplate-ui/templateRenderingStrategy/clientStrategy.js';
5
+ import { FieldConfig_Selection, FormFieldValue_SelectionValue, } from '@devvit/protos';
6
+ import { renderFieldLabel } from '../fields/index.js';
7
+ import { styles } from '../../../styles.js';
8
+ import '@reddit/faceplate-ui/components/faceplate-radio-input.js';
9
+ import '@reddit/faceplate-ui/components/faceplate-checkbox-input.js';
10
+ import { InputElement } from '@reddit/faceplate/base-classes/input-element.js';
11
+ export class DevvitFormSelectionList extends InputElement {
12
+ constructor() {
13
+ super(...arguments);
14
+ _DevvitFormSelectionList_config.set(this, FieldConfig_Selection.fromPartial({}));
15
+ _DevvitFormSelectionList_selection.set(this, FormFieldValue_SelectionValue.fromPartial({}));
16
+ _DevvitFormSelectionList_updateSelection.set(this, (choice, selected = true) => {
17
+ if (__classPrivateFieldGet(this, _DevvitFormSelectionList_config, "f").multiSelect) {
18
+ const index = __classPrivateFieldGet(this, _DevvitFormSelectionList_selection, "f").values.indexOf(choice.value);
19
+ if (selected && index < 0) {
20
+ __classPrivateFieldGet(this, _DevvitFormSelectionList_selection, "f").values.push(choice.value);
21
+ }
22
+ else if (index >= 0) {
23
+ __classPrivateFieldGet(this, _DevvitFormSelectionList_selection, "f").values.splice(index, 1);
24
+ }
25
+ }
26
+ else {
27
+ __classPrivateFieldGet(this, _DevvitFormSelectionList_selection, "f").values = [choice.value];
28
+ }
29
+ });
30
+ }
31
+ static get styles() {
32
+ return [super.styles, styles];
33
+ }
34
+ get value() {
35
+ return __classPrivateFieldGet(this, _DevvitFormSelectionList_selection, "f").values.join(',');
36
+ }
37
+ willUpdate(changedProperties) {
38
+ if (changedProperties.has('field')) {
39
+ __classPrivateFieldSet(this, _DevvitFormSelectionList_config, this.field?.fieldConfig?.selectionConfig ?? FieldConfig_Selection.fromPartial({}), "f");
40
+ __classPrivateFieldSet(this, _DevvitFormSelectionList_selection, this.field?.defaultValue?.selectionValue ?? FormFieldValue_SelectionValue.fromPartial({}), "f");
41
+ }
42
+ }
43
+ render() {
44
+ let formField;
45
+ if (this.field) {
46
+ const renderRadio = (choice, index) => {
47
+ const id = `${this.field?.fieldId}_${index}`;
48
+ return html `
49
+ <faceplate-radio-input
50
+ id="${id}"
51
+ name="${this.field?.fieldId}"
52
+ data-value="${choice.value}"
53
+ ?disabled="${this.field?.disabled}"
54
+ ?required="${this.field?.required}"
55
+ @input="${() => {
56
+ __classPrivateFieldGet(this, _DevvitFormSelectionList_updateSelection, "f").call(this, choice);
57
+ }}"
58
+ >
59
+ ${choice.label}
60
+ </faceplate-radio-input>
61
+ `;
62
+ };
63
+ const renderCheckbox = (choice, index) => {
64
+ const id = `${this.field?.fieldId}_${index}`;
65
+ return html `
66
+ <faceplate-checkbox-input
67
+ id="${id}"
68
+ name="${this.field?.fieldId}"
69
+ class="m-sm"
70
+ data-value="${choice.value}"
71
+ @input="${(ev) => {
72
+ __classPrivateFieldGet(this, _DevvitFormSelectionList_updateSelection, "f").call(this, choice, ev.currentTarget.checked);
73
+ }}"
74
+ >
75
+ ${choice.label}
76
+ </faceplate-checkbox-input>
77
+ `;
78
+ };
79
+ formField = html `${renderFieldLabel(this.field)}${repeat(__classPrivateFieldGet(this, _DevvitFormSelectionList_config, "f").choices ?? [], __classPrivateFieldGet(this, _DevvitFormSelectionList_config, "f").multiSelect === true ? renderCheckbox : renderRadio)}`;
80
+ }
81
+ return html `${formField}${super.render()}`;
82
+ }
83
+ }
84
+ _DevvitFormSelectionList_config = new WeakMap(), _DevvitFormSelectionList_selection = new WeakMap(), _DevvitFormSelectionList_updateSelection = new WeakMap();
85
+ __decorate([
86
+ property({ attribute: false }),
87
+ __metadata("design:type", Object)
88
+ ], DevvitFormSelectionList.prototype, "field", void 0);
89
+ // Faceplate's base classes and mixins aren't playing nice with type checking for some reason
90
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
91
+ customElements.define('devvit-form-selection-list', DevvitFormSelectionList);
@@ -0,0 +1,17 @@
1
+ import { LitElement } from 'lit';
2
+ import '@reddit/faceplate-ui/templateRenderingStrategy/clientStrategy.js';
3
+ import { FaceplateDialog } from '@reddit/faceplate-ui/components/faceplate-dialog.js';
4
+ import { FaceplateForm } from '@reddit/faceplate/components/faceplate-form.js';
5
+ import { Form, UIEvent } from '@devvit/protos';
6
+ import '@reddit/faceplate-ui/components/faceplate-dialog';
7
+ import '@reddit/faceplate/components/faceplate-form.js';
8
+ export declare class DevvitFormDialog extends LitElement {
9
+ #private;
10
+ form: Form | undefined;
11
+ $dialog?: FaceplateDialog;
12
+ $form?: FaceplateForm;
13
+ static get styles(): import("lit").CSSResult[];
14
+ showForm(form: Form, onEvent: (event: UIEvent) => void): void;
15
+ render(): import("lit-html").TemplateResult<1>;
16
+ }
17
+ //# sourceMappingURL=devvit-form-dialog.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"devvit-form-dialog.d.ts","sourceRoot":"","sources":["../../../src/client/formbuilder/devvit-form-dialog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,UAAU,EAAE,MAAM,KAAK,CAAC;AAIvC,OAAO,kEAAkE,CAAC;AAE1E,OAAO,EAAE,eAAe,EAAE,MAAM,qDAAqD,CAAC;AAItF,OAAO,EAAE,aAAa,EAAoB,MAAM,gDAAgD,CAAC;AAEjG,OAAO,EAAE,IAAI,EAA4C,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAKzF,OAAO,kDAAkD,CAAC;AAC1D,OAAO,gDAAgD,CAAC;AAKxD,qBACa,gBAAiB,SAAQ,UAAU;;IAE9C,IAAI,EAAE,IAAI,GAAG,SAAS,CAAC;IAGvB,OAAO,CAAC,EAAE,eAAe,CAAC;IAG1B,KAAK,CAAC,EAAE,aAAa,CAAC;IAKtB,WAAoB,MAAM,8BAEzB;IAED,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI;IA6E7C,MAAM;CA+ChB"}