@nyaruka/temba-components 0.129.9 → 0.129.10

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 (118) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/demo/test-colorpicker.html +30 -0
  3. package/dist/temba-components.js +867 -915
  4. package/dist/temba-components.js.map +1 -1
  5. package/out-tsc/src/events.js.map +1 -1
  6. package/out-tsc/src/form/ArrayEditor.js +45 -56
  7. package/out-tsc/src/form/ArrayEditor.js.map +1 -1
  8. package/out-tsc/src/form/BaseListEditor.js +4 -3
  9. package/out-tsc/src/form/BaseListEditor.js.map +1 -1
  10. package/out-tsc/src/form/Checkbox.js +77 -24
  11. package/out-tsc/src/form/Checkbox.js.map +1 -1
  12. package/out-tsc/src/form/ColorPicker.js +28 -40
  13. package/out-tsc/src/form/ColorPicker.js.map +1 -1
  14. package/out-tsc/src/form/Completion.js +44 -53
  15. package/out-tsc/src/form/Completion.js.map +1 -1
  16. package/out-tsc/src/form/Compose.js +7 -8
  17. package/out-tsc/src/form/Compose.js.map +1 -1
  18. package/out-tsc/src/form/ContactSearch.js +3 -4
  19. package/out-tsc/src/form/ContactSearch.js.map +1 -1
  20. package/out-tsc/src/form/DatePicker.js +29 -36
  21. package/out-tsc/src/form/DatePicker.js.map +1 -1
  22. package/out-tsc/src/form/{FormField.js → FieldElement.js} +78 -50
  23. package/out-tsc/src/form/FieldElement.js.map +1 -0
  24. package/out-tsc/src/form/FieldRenderer.js +2 -1
  25. package/out-tsc/src/form/FieldRenderer.js.map +1 -1
  26. package/out-tsc/src/form/ImagePicker.js +122 -126
  27. package/out-tsc/src/form/ImagePicker.js.map +1 -1
  28. package/out-tsc/src/form/KeyValueEditor.js +41 -37
  29. package/out-tsc/src/form/KeyValueEditor.js.map +1 -1
  30. package/out-tsc/src/form/MessageEditor.js +55 -63
  31. package/out-tsc/src/form/MessageEditor.js.map +1 -1
  32. package/out-tsc/src/form/TembaSlider.js +3 -3
  33. package/out-tsc/src/form/TembaSlider.js.map +1 -1
  34. package/out-tsc/src/form/TemplateEditor.js +3 -3
  35. package/out-tsc/src/form/TemplateEditor.js.map +1 -1
  36. package/out-tsc/src/form/TextInput.js +22 -26
  37. package/out-tsc/src/form/TextInput.js.map +1 -1
  38. package/out-tsc/src/form/select/Select.js +9 -15
  39. package/out-tsc/src/form/select/Select.js.map +1 -1
  40. package/out-tsc/src/form/select/UserSelect.js +8 -9
  41. package/out-tsc/src/form/select/UserSelect.js.map +1 -1
  42. package/out-tsc/src/form/select/WorkspaceSelect.js +7 -8
  43. package/out-tsc/src/form/select/WorkspaceSelect.js.map +1 -1
  44. package/out-tsc/src/live/ContactChat.js +32 -40
  45. package/out-tsc/src/live/ContactChat.js.map +1 -1
  46. package/out-tsc/src/live/ContactFieldEditor.js.map +1 -1
  47. package/out-tsc/temba-modules.js +3 -2
  48. package/out-tsc/temba-modules.js.map +1 -1
  49. package/out-tsc/test/temba-checkbox.test.js +16 -0
  50. package/out-tsc/test/temba-checkbox.test.js.map +1 -1
  51. package/out-tsc/test/temba-integration-markdown.test.js +2 -4
  52. package/out-tsc/test/temba-integration-markdown.test.js.map +1 -1
  53. package/out-tsc/test/temba-slider.test.js +0 -1
  54. package/out-tsc/test/temba-slider.test.js.map +1 -1
  55. package/package.json +1 -1
  56. package/screenshots/truth/actions/call_llm/editor/information-extraction.png +0 -0
  57. package/screenshots/truth/actions/call_llm/editor/sentiment-analysis.png +0 -0
  58. package/screenshots/truth/actions/call_llm/editor/summarization.png +0 -0
  59. package/screenshots/truth/actions/call_llm/editor/translation-task.png +0 -0
  60. package/screenshots/truth/actions/remove_contact_groups/editor/cleanup-groups.png +0 -0
  61. package/screenshots/truth/actions/remove_contact_groups/editor/long-descriptive-group-names.png +0 -0
  62. package/screenshots/truth/actions/remove_contact_groups/editor/many-groups.png +0 -0
  63. package/screenshots/truth/actions/remove_contact_groups/editor/multiple-groups.png +0 -0
  64. package/screenshots/truth/actions/remove_contact_groups/editor/remove-from-all-groups.png +0 -0
  65. package/screenshots/truth/actions/remove_contact_groups/editor/single-group.png +0 -0
  66. package/screenshots/truth/checkbox/checkbox-label-background-hover.png +0 -0
  67. package/screenshots/truth/checkbox/checkbox-no-label-no-background-hover.png +0 -0
  68. package/screenshots/truth/checkbox/checkbox-with-help-text.png +0 -0
  69. package/screenshots/truth/checkbox/checked.png +0 -0
  70. package/screenshots/truth/checkbox/default.png +0 -0
  71. package/screenshots/truth/colorpicker/default.png +0 -0
  72. package/screenshots/truth/colorpicker/focused.png +0 -0
  73. package/screenshots/truth/colorpicker/initialized.png +0 -0
  74. package/screenshots/truth/colorpicker/selected.png +0 -0
  75. package/screenshots/truth/field-renderer/checkbox-checked.png +0 -0
  76. package/screenshots/truth/field-renderer/checkbox-unchecked.png +0 -0
  77. package/screenshots/truth/field-renderer/checkbox-with-errors.png +0 -0
  78. package/screenshots/truth/integration/checkbox-markdown-errors.png +0 -0
  79. package/screenshots/truth/nodes/split_by_llm_categorize/editor/basic-categorization.png +0 -0
  80. package/screenshots/truth/nodes/split_by_llm_categorize/editor/custom-input-and-result-name.png +0 -0
  81. package/screenshots/truth/nodes/split_by_llm_categorize/editor/feedback-categorization.png +0 -0
  82. package/screenshots/truth/nodes/split_by_llm_categorize/editor/many-categories.png +0 -0
  83. package/screenshots/truth/nodes/split_by_llm_categorize/editor/minimal-categories.png +0 -0
  84. package/screenshots/truth/run-list/basic.png +0 -0
  85. package/src/events.ts +5 -6
  86. package/src/form/ArrayEditor.ts +45 -57
  87. package/src/form/BaseListEditor.ts +4 -4
  88. package/src/form/Checkbox.ts +81 -24
  89. package/src/form/ColorPicker.ts +31 -43
  90. package/src/form/Completion.ts +49 -56
  91. package/src/form/Compose.ts +8 -8
  92. package/src/form/ContactSearch.ts +3 -4
  93. package/src/form/DatePicker.ts +32 -38
  94. package/src/form/{FormField.ts → FieldElement.ts} +105 -52
  95. package/src/form/FieldRenderer.ts +2 -1
  96. package/src/form/ImagePicker.ts +107 -110
  97. package/src/form/KeyValueEditor.ts +43 -39
  98. package/src/form/MessageEditor.ts +61 -67
  99. package/src/form/TembaSlider.ts +3 -3
  100. package/src/form/TemplateEditor.ts +3 -3
  101. package/src/form/TextInput.ts +25 -28
  102. package/src/form/select/Select.ts +12 -17
  103. package/src/form/select/UserSelect.ts +10 -11
  104. package/src/form/select/WorkspaceSelect.ts +9 -10
  105. package/src/live/ContactChat.ts +32 -41
  106. package/src/live/ContactFieldEditor.ts +2 -2
  107. package/temba-modules.ts +3 -2
  108. package/test/temba-checkbox.test.ts +26 -0
  109. package/test/temba-integration-markdown.test.ts +2 -4
  110. package/test/temba-slider.test.ts +0 -1
  111. package/test-assets/contacts/history.json +7 -20
  112. package/out-tsc/src/form/FormElement.js +0 -67
  113. package/out-tsc/src/form/FormElement.js.map +0 -1
  114. package/out-tsc/src/form/FormField.js.map +0 -1
  115. package/out-tsc/test/temba-formfield.test.js +0 -94
  116. package/out-tsc/test/temba-formfield.test.js.map +0 -1
  117. package/src/form/FormElement.ts +0 -69
  118. package/test/temba-formfield.test.ts +0 -121
@@ -15,7 +15,6 @@ describe('temba-slider', () => {
15
15
  <temba-slider label="My Slider"></temba-slider>
16
16
  `);
17
17
 
18
- expect(slider.label).to.equal('My Slider');
19
18
  await assertScreenshot('slider/default', getClip(slider));
20
19
  });
21
20
 
@@ -62,13 +62,14 @@
62
62
  "logs_url": null
63
63
  },
64
64
  {
65
- "type": "flow_exited",
66
- "created_on": "2021-03-30T22:20:35.573809+00:00",
65
+ "type": "run_ended",
66
+ "created_on": "2021-03-30T22:20:26.704467+00:00",
67
+ "run_uuid": "0198c846-da2b-799f-8af9-aaf8857f947f",
67
68
  "flow": {
68
69
  "uuid": "d076d716-8071-417e-b188-d9746db223a1",
69
70
  "name": "Favorites"
70
71
  },
71
- "status": "C"
72
+ "status": "completed"
72
73
  },
73
74
  {
74
75
  "uuid": "01988a70-3e8f-7890-b1d2-7418db7a575e",
@@ -209,13 +210,9 @@
209
210
  "logs_url": "/channels/channellog/read/1472/"
210
211
  },
211
212
  {
212
- "type": "flow_entered",
213
- "created_on": "2021-03-30T22:20:26.704467+00:00",
214
- "flow": {
215
- "uuid": "d076d716-8071-417e-b188-d9746db223a1",
216
- "name": "Favorites"
217
- },
218
- "logs_url": null
213
+ "uuid": "0198e7b8-fe00-76e6-91e4-1253dd9a6230",
214
+ "type": "call_missed",
215
+ "created_on": "2021-03-30T22:20:26.704467+00:00"
219
216
  },
220
217
  {
221
218
  "type": "run_started",
@@ -226,16 +223,6 @@
226
223
  "name": "Favorites"
227
224
  }
228
225
  },
229
- {
230
- "type": "run_ended",
231
- "created_on": "2021-03-30T22:20:26.704467+00:00",
232
- "run_uuid": "0198c846-da2b-799f-8af9-aaf8857f947f",
233
- "flow": {
234
- "uuid": "d076d716-8071-417e-b188-d9746db223a1",
235
- "name": "Favorites"
236
- },
237
- "status": "completed"
238
- },
239
226
  {
240
227
  "uuid": "01988a77-979e-7768-a940-8d9c348e24fe",
241
228
  "type": "msg_received",
@@ -1,67 +0,0 @@
1
- import { __decorate } from "tslib";
2
- import { RapidElement } from '../RapidElement';
3
- import { property } from 'lit/decorators.js';
4
- /**
5
- * FormElement is a component that appends a hidden input (outside of
6
- * its own shadow) with its value to be included in forms.
7
- */
8
- export class FormElement extends RapidElement {
9
- constructor() {
10
- super();
11
- this.name = '';
12
- this.value = null;
13
- this.inputRoot = this;
14
- this.disabled = false;
15
- this.internals = this.attachInternals();
16
- }
17
- updated(changedProperties) {
18
- super.updated(changedProperties);
19
- if (changedProperties.has('value')) {
20
- this.internals.setFormValue(this.value);
21
- }
22
- }
23
- get form() {
24
- return this.internals.form;
25
- }
26
- setValue(value) {
27
- this.value = this.serializeValue(value);
28
- }
29
- getDeserializedValue() {
30
- return JSON.parse(this.value);
31
- }
32
- serializeValue(value) {
33
- return JSON.stringify(value);
34
- }
35
- }
36
- FormElement.formAssociated = true;
37
- __decorate([
38
- property({ type: String })
39
- ], FormElement.prototype, "name", void 0);
40
- __decorate([
41
- property({ type: String, attribute: 'help_text' })
42
- ], FormElement.prototype, "helpText", void 0);
43
- __decorate([
44
- property({ type: Boolean, attribute: 'help_always' })
45
- ], FormElement.prototype, "helpAlways", void 0);
46
- __decorate([
47
- property({ type: Boolean, attribute: 'widget_only' })
48
- ], FormElement.prototype, "widgetOnly", void 0);
49
- __decorate([
50
- property({ type: Boolean, attribute: 'hide_label' })
51
- ], FormElement.prototype, "hideLabel", void 0);
52
- __decorate([
53
- property({ type: String })
54
- ], FormElement.prototype, "label", void 0);
55
- __decorate([
56
- property({ type: Array })
57
- ], FormElement.prototype, "errors", void 0);
58
- __decorate([
59
- property({ type: String })
60
- ], FormElement.prototype, "value", void 0);
61
- __decorate([
62
- property({ attribute: false })
63
- ], FormElement.prototype, "inputRoot", void 0);
64
- __decorate([
65
- property({ type: Boolean })
66
- ], FormElement.prototype, "disabled", void 0);
67
- //# sourceMappingURL=FormElement.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"FormElement.js","sourceRoot":"","sources":["../../../src/form/FormElement.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C;;;GAGG;AACH,MAAM,OAAO,WAAY,SAAQ,YAAY;IAkC3C;QACE,KAAK,EAAE,CAAC;QAjCV,SAAI,GAAG,EAAE,CAAC;QAqBV,UAAK,GAAG,IAAI,CAAC;QAGb,cAAS,GAAgB,IAAI,CAAC;QAG9B,aAAQ,GAAG,KAAK,CAAC;QAOf,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC;IAC1C,CAAC;IAEM,OAAO,CAAC,iBAAmC;QAChD,KAAK,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;QACjC,IAAI,iBAAiB,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;YACnC,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,IAA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6CACX","sourcesContent":["import { RapidElement } from '../RapidElement';\nimport { property } from 'lit/decorators.js';\n\n/**\n * FormElement is a component that appends a hidden input (outside of\n * its own shadow) with its value to be included in forms.\n */\nexport class FormElement extends RapidElement {\n @property({ type: String })\n name = '';\n\n @property({ type: String, attribute: 'help_text' })\n helpText: string;\n\n @property({ type: Boolean, attribute: 'help_always' })\n helpAlways: boolean;\n\n @property({ type: Boolean, attribute: 'widget_only' })\n widgetOnly: boolean;\n\n @property({ type: Boolean, attribute: 'hide_label' })\n hideLabel: boolean;\n\n @property({ type: String })\n label: string;\n\n @property({ type: Array })\n errors: string[];\n\n @property({ type: String })\n value = null;\n\n @property({ attribute: false })\n inputRoot: HTMLElement = this;\n\n @property({ type: Boolean })\n disabled = false;\n static formAssociated = true;\n\n protected internals: ElementInternals;\n\n constructor() {\n super();\n this.internals = this.attachInternals();\n }\n\n public updated(changedProperties: Map<string, any>) {\n super.updated(changedProperties);\n if (changedProperties.has('value')) {\n this.internals.setFormValue(this.value);\n }\n }\n\n get form() {\n return this.internals.form;\n }\n\n public setValue(value: any) {\n this.value = this.serializeValue(value);\n }\n\n public getDeserializedValue(): any {\n return JSON.parse(this.value);\n }\n\n public serializeValue(value: any): string {\n return JSON.stringify(value);\n }\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"FormField.js","sourceRoot":"","sources":["../../../src/form/FormField.ts"],"names":[],"mappings":";AAAA,OAAO,EAAkB,IAAI,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AAC5D,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD;;;GAGG;AACH,MAAM,OAAO,SAAU,SAAQ,UAAU;IAAzC;;QAkJE,cAAS,GAAG,KAAK,CAAC;QAGlB,eAAU,GAAG,KAAK,CAAC;QAGnB,WAAM,GAAa,EAAE,CAAC;QAGtB,eAAU,GAAG,KAAK,C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ACrC;AAGd;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,CAAC;6CACpC;AAGlB;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;wCAChB;AAGX;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;uCACjB;AAGV;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;2CACX","sourcesContent":["import { TemplateResult, html, css, LitElement } from 'lit';\nimport { property } from 'lit/decorators.js';\nimport { renderMarkdownInline } from '../markdown';\n\n/**\n * A small wrapper to display labels and help text in a smartmin style.\n * This exists so we can display things consistently before restyling.\n */\nexport class FormField extends LitElement {\n static get styles() {\n return css`\n :host {\n font-family: var(--font-family);\n }\n\n label {\n margin-bottom: 5px;\n margin-left: 4px;\n display: block;\n font-weight: 400;\n font-size: var(--label-size);\n letter-spacing: 0.05em;\n line-height: normal;\n color: var(--color-label, #777);\n }\n\n .help-text {\n font-size: var(--help-text-size);\n line-height: normal;\n color: var(--color-text-help);\n margin-left: var(--help-text-margin-left);\n margin-top: -16px;\n opacity: 0;\n transition: opacity ease-in-out 100ms, margin-top ease-in-out 200ms;\n pointer-events: none;\n }\n\n .help-text.help-always {\n opacity: 1;\n margin-top: 6px;\n margin-left: var(--help-text-margin-left);\n }\n\n .field:focus-within .help-text {\n margin-top: 6px;\n opacity: 1;\n }\n\n .alert-error {\n position: absolute;\n top: 100%;\n left: 0;\n right: 0;\n z-index: 1000;\n background: white;\n border: 1px solid var(--color-error);\n color: var(--color-error);\n padding: 8px 12px;\n margin: 2px 0 0 0;\n border-radius: var(--curvature);\n box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1),\n 0 2px 4px -1px rgba(0, 0, 0, 0.06);\n font-size: 0.85em;\n line-height: 1.2;\n opacity: 0;\n visibility: hidden;\n transform: translateY(-12px);\n transition: opacity 0.2s ease-in-out, visibility 0.2s ease-in-out,\n transform 0.2s ease-in-out;\n }\n\n .field:hover .alert-error {\n opacity: 1;\n visibility: visible;\n transform: translateY(2px);\n }\n\n /* Hide error popup when widget is focused */\n .field:focus-within .alert-error {\n opacity: 0;\n visibility: hidden;\n transform: translateY(-4px);\n }\n\n .field.has-error {\n position: relative;\n /* Set CSS custom properties that form components can use */\n --color-widget-border: var(--color-error);\n --widget-box-shadow-focused: var(\n --widget-box-shadow-focused-error,\n 0 0 0 3px rgba(255, 99, 71, 0.3)\n );\n --color-focus: var(--color-error);\n }\n\n .field.has-error .widget {\n border-radius: var(--curvature-widget);\n position: relative;\n }\n\n /* Force error styling with higher specificity */\n :host(.has-error) .field.has-error .widget .input-container,\n :host(.has-error) .field.has-error .widget .select-container,\n :host(.has-error) .field.has-error .widget .comp-container,\n :host(.has-error) .field.has-error .widget .checkbox-container,\n :host(.has-error) .field.has-error .widget .container,\n :host(.has-error) .field.has-error .widget .range-container,\n .field.has-error .widget .input-container,\n .field.has-error .widget .select-container,\n .field.has-error .widget .comp-container,\n .field.has-error .widget .checkbox-container,\n .field.has-error .widget .container,\n .field.has-error .widget .range-container {\n border-color: var(--color-error) !important;\n }\n\n /* When error field is focused, use error-colored focus ring */\n :host(.has-error) .field.has-error .widget .input-container:focus-within,\n :host(.has-error) .field.has-error .widget .select-container:focus-within,\n :host(.has-error) .field.has-error .widget .select-container.focused,\n :host(.has-error) .field.has-error .widget .comp-container:focus-within,\n :host(.has-error)\n .field.has-error\n .widget\n .checkbox-container:focus-within,\n :host(.has-error) .field.has-error .widget .container:focus-within,\n :host(.has-error) .field.has-error .widget .range-container:focus-within,\n .field.has-error .widget .input-container:focus-within,\n .field.has-error .widget .select-container:focus-within,\n .field.has-error .widget .select-container.focused,\n .field.has-error .widget .comp-container:focus-within,\n .field.has-error .widget .checkbox-container:focus-within,\n .field.has-error .widget .container:focus-within,\n .field.has-error .widget .range-container:focus-within {\n border-color: var(--color-error) !important;\n box-shadow: var(\n --widget-box-shadow-focused-error,\n 0 0 0 3px rgba(255, 99, 71, 0.3)\n ) !important;\n }\n\n .alert-error p {\n margin: 0;\n padding: 0;\n }\n\n .disabled {\n opacity: var(--disabled-opacity) !important;\n pointer-events: none !important;\n }\n `;\n }\n\n @property({ type: Boolean, attribute: 'hide_label' })\n hideLabel = false;\n\n @property({ type: Boolean, attribute: 'widget_only' })\n widgetOnly = false;\n\n @property({ type: Array, attribute: false })\n errors: string[] = [];\n\n @property({ type: Boolean })\n hideErrors = false;\n\n @property({ type: String, attribute: 'help_text' })\n helpText = '';\n\n @property({ type: Boolean, attribute: 'help_always' })\n helpAlways = true;\n\n @property({ type: String })\n label = '';\n\n @property({ type: String })\n name = '';\n\n @property({ type: Boolean })\n disabled = false;\n\n updated(changedProperties: Map<string | number | symbol, unknown>): void {\n super.updated(changedProperties);\n\n if (\n changedProperties.has('errors') ||\n changedProperties.has('hideErrors')\n ) {\n const hasErrors =\n !this.hideErrors && this.errors && this.errors.length > 0;\n this.classList.toggle('has-error', hasErrors);\n }\n }\n\n public render(): TemplateResult {\n const hasErrors = !this.hideErrors && this.errors && this.errors.length > 0;\n const errors = hasErrors\n ? this.errors.map((error: string) => {\n return html`\n <div class=\"alert-error\">${renderMarkdownInline(error)}</div>\n `;\n })\n : [];\n\n if (this.widgetOnly) {\n return html`\n <div class=\"${this.disabled ? 'disabled' : ''}\"><slot></slot></div>\n ${errors}\n `;\n }\n\n return html`\n <div\n class=\"field ${this.disabled ? 'disabled' : ''} ${hasErrors\n ? 'has-error'\n : ''}\"\n >\n ${!!this.name && !this.hideLabel && !!this.label\n ? html`\n <label class=\"control-label\" for=\"${this.name}\"\n >${this.label}</label\n >\n `\n : null}\n <div class=\"widget\">\n <slot></slot>\n ${errors}\n </div>\n ${this.helpText && this.helpText !== 'None'\n ? html`\n <div class=\"help-text ${this.helpAlways ? 'help-always' : null}\">\n ${renderMarkdownInline(this.helpText)}\n </div>\n `\n : null}\n </div>\n `;\n }\n}\n"]}
@@ -1,94 +0,0 @@
1
- import { html, fixture, expect } from '@open-wc/testing';
2
- import { assertScreenshot, getClip } from './utils.test';
3
- describe('temba-field', () => {
4
- it('renders field with plain text errors', async () => {
5
- const formField = await fixture(html `
6
- <temba-field
7
- label="Test Field"
8
- name="test"
9
- .errors=${['This is a plain text error', 'Another error message']}
10
- >
11
- <input type="text" />
12
- </temba-field>
13
- `);
14
- await formField.updateComplete;
15
- // Check that errors are rendered
16
- const errorElements = formField.shadowRoot.querySelectorAll('.alert-error');
17
- expect(errorElements.length).to.equal(2);
18
- expect(errorElements[0].textContent.trim()).to.equal('This is a plain text error');
19
- expect(errorElements[1].textContent.trim()).to.equal('Another error message');
20
- await assertScreenshot('formfield/plain-text-errors', getClip(formField));
21
- });
22
- it('renders field with markdown errors', async () => {
23
- const formField = await fixture(html `
24
- <temba-field
25
- label="Test Field"
26
- name="test"
27
- .errors=${[
28
- 'This is **bold** text',
29
- 'This has a [link](https://example.com)',
30
- 'This is *italic* and **bold** with a [link](https://example.com)'
31
- ]}
32
- >
33
- <input type="text" />
34
- </temba-field>
35
- `);
36
- await formField.updateComplete;
37
- // Check that errors are rendered
38
- const errorElements = formField.shadowRoot.querySelectorAll('.alert-error');
39
- expect(errorElements.length).to.equal(3);
40
- // First error should have bold text
41
- const firstError = errorElements[0];
42
- const boldElement = firstError.querySelector('strong');
43
- expect(boldElement).to.not.be.null;
44
- expect(boldElement.textContent).to.equal('bold');
45
- // Second error should have a link
46
- const secondError = errorElements[1];
47
- const linkElement = secondError.querySelector('a');
48
- expect(linkElement).to.not.be.null;
49
- expect(linkElement.getAttribute('href')).to.equal('https://example.com');
50
- expect(linkElement.textContent).to.equal('link');
51
- // Third error should have both bold, italic, and link
52
- const thirdError = errorElements[2];
53
- const thirdBoldElement = thirdError.querySelector('strong');
54
- const thirdItalicElement = thirdError.querySelector('em');
55
- const thirdLinkElement = thirdError.querySelector('a');
56
- expect(thirdBoldElement).to.not.be.null;
57
- expect(thirdItalicElement).to.not.be.null;
58
- expect(thirdLinkElement).to.not.be.null;
59
- await assertScreenshot('formfield/markdown-errors', getClip(formField));
60
- });
61
- it('renders field without errors', async () => {
62
- const formField = await fixture(html `
63
- <temba-field label="Test Field" name="test">
64
- <input type="text" />
65
- </temba-field>
66
- `);
67
- await formField.updateComplete;
68
- // Check that no errors are rendered
69
- const errorElements = formField.shadowRoot.querySelectorAll('.alert-error');
70
- expect(errorElements.length).to.equal(0);
71
- await assertScreenshot('formfield/no-errors', getClip(formField));
72
- });
73
- it('renders in widget-only mode with errors', async () => {
74
- const formField = await fixture(html `
75
- <temba-field
76
- widget_only
77
- .errors=${['Widget only **error** with [link](https://example.com)']}
78
- >
79
- <input type="text" />
80
- </temba-field>
81
- `);
82
- await formField.updateComplete;
83
- // Check that error is rendered in widget-only mode
84
- const errorElements = formField.shadowRoot.querySelectorAll('.alert-error');
85
- expect(errorElements.length).to.equal(1);
86
- const errorElement = errorElements[0];
87
- const boldElement = errorElement.querySelector('strong');
88
- const linkElement = errorElement.querySelector('a');
89
- expect(boldElement).to.not.be.null;
90
- expect(linkElement).to.not.be.null;
91
- await assertScreenshot('formfield/widget-only-markdown-errors', getClip(formField));
92
- });
93
- });
94
- //# sourceMappingURL=temba-formfield.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"temba-formfield.test.js","sourceRoot":"","sources":["../../test/temba-formfield.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAEzD,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEzD,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAC3B,EAAE,CAAC,sCAAsC,EAAE,KAAK,IAAI,EAAE;QACpD,MAAM,SAAS,GAAc,MAAM,OAAO,CAAC,IAAI,CAAA;;;;kBAIjC,CAAC,4BAA4B,EAAE,uBAAuB,CAAC;;;;KAIpE,CAAC,CAAC;QAEH,MAAM,SAAS,CAAC,cAAc,C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nimport { FormField } from '../src/form/FormField';\nimport { assertScreenshot, getClip } from './utils.test';\n\ndescribe('temba-field', () => {\n it('renders field with plain text errors', async () => {\n const formField: FormField = await fixture(html`\n <temba-field\n label=\"Test Field\"\n name=\"test\"\n .errors=${['This is a plain text error', 'Another error message']}\n >\n <input type=\"text\" />\n </temba-field>\n `);\n\n await formField.updateComplete;\n\n // Check that errors are rendered\n const errorElements = formField.shadowRoot.querySelectorAll('.alert-error');\n expect(errorElements.length).to.equal(2);\n expect(errorElements[0].textContent.trim()).to.equal(\n 'This is a plain text error'\n );\n expect(errorElements[1].textContent.trim()).to.equal(\n 'Another error message'\n );\n\n await assertScreenshot('formfield/plain-text-errors', getClip(formField));\n });\n\n it('renders field with markdown errors', async () => {\n const formField: FormField = await fixture(html`\n <temba-field\n label=\"Test Field\"\n name=\"test\"\n .errors=${[\n 'This is **bold** text',\n 'This has a [link](https://example.com)',\n 'This is *italic* and **bold** with a [link](https://example.com)'\n ]}\n >\n <input type=\"text\" />\n </temba-field>\n `);\n\n await formField.updateComplete;\n\n // Check that errors are rendered\n const errorElements = formField.shadowRoot.querySelectorAll('.alert-error');\n expect(errorElements.length).to.equal(3);\n\n // First error should have bold text\n const firstError = errorElements[0];\n const boldElement = firstError.querySelector('strong');\n expect(boldElement).to.not.be.null;\n expect(boldElement.textContent).to.equal('bold');\n\n // Second error should have a link\n const secondError = errorElements[1];\n const linkElement = secondError.querySelector('a');\n expect(linkElement).to.not.be.null;\n expect(linkElement.getAttribute('href')).to.equal('https://example.com');\n expect(linkElement.textContent).to.equal('link');\n\n // Third error should have both bold, italic, and link\n const thirdError = errorElements[2];\n const thirdBoldElement = thirdError.querySelector('strong');\n const thirdItalicElement = thirdError.querySelector('em');\n const thirdLinkElement = thirdError.querySelector('a');\n expect(thirdBoldElement).to.not.be.null;\n expect(thirdItalicElement).to.not.be.null;\n expect(thirdLinkElement).to.not.be.null;\n\n await assertScreenshot('formfield/markdown-errors', getClip(formField));\n });\n\n it('renders field without errors', async () => {\n const formField: FormField = await fixture(html`\n <temba-field label=\"Test Field\" name=\"test\">\n <input type=\"text\" />\n </temba-field>\n `);\n\n await formField.updateComplete;\n\n // Check that no errors are rendered\n const errorElements = formField.shadowRoot.querySelectorAll('.alert-error');\n expect(errorElements.length).to.equal(0);\n\n await assertScreenshot('formfield/no-errors', getClip(formField));\n });\n\n it('renders in widget-only mode with errors', async () => {\n const formField: FormField = await fixture(html`\n <temba-field\n widget_only\n .errors=${['Widget only **error** with [link](https://example.com)']}\n >\n <input type=\"text\" />\n </temba-field>\n `);\n\n await formField.updateComplete;\n\n // Check that error is rendered in widget-only mode\n const errorElements = formField.shadowRoot.querySelectorAll('.alert-error');\n expect(errorElements.length).to.equal(1);\n\n const errorElement = errorElements[0];\n const boldElement = errorElement.querySelector('strong');\n const linkElement = errorElement.querySelector('a');\n expect(boldElement).to.not.be.null;\n expect(linkElement).to.not.be.null;\n\n await assertScreenshot(\n 'formfield/widget-only-markdown-errors',\n getClip(formField)\n );\n });\n});\n"]}
@@ -1,69 +0,0 @@
1
- import { RapidElement } from '../RapidElement';
2
- import { property } from 'lit/decorators.js';
3
-
4
- /**
5
- * FormElement is a component that appends a hidden input (outside of
6
- * its own shadow) with its value to be included in forms.
7
- */
8
- export class FormElement extends RapidElement {
9
- @property({ type: String })
10
- name = '';
11
-
12
- @property({ type: String, attribute: 'help_text' })
13
- helpText: string;
14
-
15
- @property({ type: Boolean, attribute: 'help_always' })
16
- helpAlways: boolean;
17
-
18
- @property({ type: Boolean, attribute: 'widget_only' })
19
- widgetOnly: boolean;
20
-
21
- @property({ type: Boolean, attribute: 'hide_label' })
22
- hideLabel: boolean;
23
-
24
- @property({ type: String })
25
- label: string;
26
-
27
- @property({ type: Array })
28
- errors: string[];
29
-
30
- @property({ type: String })
31
- value = null;
32
-
33
- @property({ attribute: false })
34
- inputRoot: HTMLElement = this;
35
-
36
- @property({ type: Boolean })
37
- disabled = false;
38
- static formAssociated = true;
39
-
40
- protected internals: ElementInternals;
41
-
42
- constructor() {
43
- super();
44
- this.internals = this.attachInternals();
45
- }
46
-
47
- public updated(changedProperties: Map<string, any>) {
48
- super.updated(changedProperties);
49
- if (changedProperties.has('value')) {
50
- this.internals.setFormValue(this.value);
51
- }
52
- }
53
-
54
- get form() {
55
- return this.internals.form;
56
- }
57
-
58
- public setValue(value: any) {
59
- this.value = this.serializeValue(value);
60
- }
61
-
62
- public getDeserializedValue(): any {
63
- return JSON.parse(this.value);
64
- }
65
-
66
- public serializeValue(value: any): string {
67
- return JSON.stringify(value);
68
- }
69
- }
@@ -1,121 +0,0 @@
1
- import { html, fixture, expect } from '@open-wc/testing';
2
- import { FormField } from '../src/form/FormField';
3
- import { assertScreenshot, getClip } from './utils.test';
4
-
5
- describe('temba-field', () => {
6
- it('renders field with plain text errors', async () => {
7
- const formField: FormField = await fixture(html`
8
- <temba-field
9
- label="Test Field"
10
- name="test"
11
- .errors=${['This is a plain text error', 'Another error message']}
12
- >
13
- <input type="text" />
14
- </temba-field>
15
- `);
16
-
17
- await formField.updateComplete;
18
-
19
- // Check that errors are rendered
20
- const errorElements = formField.shadowRoot.querySelectorAll('.alert-error');
21
- expect(errorElements.length).to.equal(2);
22
- expect(errorElements[0].textContent.trim()).to.equal(
23
- 'This is a plain text error'
24
- );
25
- expect(errorElements[1].textContent.trim()).to.equal(
26
- 'Another error message'
27
- );
28
-
29
- await assertScreenshot('formfield/plain-text-errors', getClip(formField));
30
- });
31
-
32
- it('renders field with markdown errors', async () => {
33
- const formField: FormField = await fixture(html`
34
- <temba-field
35
- label="Test Field"
36
- name="test"
37
- .errors=${[
38
- 'This is **bold** text',
39
- 'This has a [link](https://example.com)',
40
- 'This is *italic* and **bold** with a [link](https://example.com)'
41
- ]}
42
- >
43
- <input type="text" />
44
- </temba-field>
45
- `);
46
-
47
- await formField.updateComplete;
48
-
49
- // Check that errors are rendered
50
- const errorElements = formField.shadowRoot.querySelectorAll('.alert-error');
51
- expect(errorElements.length).to.equal(3);
52
-
53
- // First error should have bold text
54
- const firstError = errorElements[0];
55
- const boldElement = firstError.querySelector('strong');
56
- expect(boldElement).to.not.be.null;
57
- expect(boldElement.textContent).to.equal('bold');
58
-
59
- // Second error should have a link
60
- const secondError = errorElements[1];
61
- const linkElement = secondError.querySelector('a');
62
- expect(linkElement).to.not.be.null;
63
- expect(linkElement.getAttribute('href')).to.equal('https://example.com');
64
- expect(linkElement.textContent).to.equal('link');
65
-
66
- // Third error should have both bold, italic, and link
67
- const thirdError = errorElements[2];
68
- const thirdBoldElement = thirdError.querySelector('strong');
69
- const thirdItalicElement = thirdError.querySelector('em');
70
- const thirdLinkElement = thirdError.querySelector('a');
71
- expect(thirdBoldElement).to.not.be.null;
72
- expect(thirdItalicElement).to.not.be.null;
73
- expect(thirdLinkElement).to.not.be.null;
74
-
75
- await assertScreenshot('formfield/markdown-errors', getClip(formField));
76
- });
77
-
78
- it('renders field without errors', async () => {
79
- const formField: FormField = await fixture(html`
80
- <temba-field label="Test Field" name="test">
81
- <input type="text" />
82
- </temba-field>
83
- `);
84
-
85
- await formField.updateComplete;
86
-
87
- // Check that no errors are rendered
88
- const errorElements = formField.shadowRoot.querySelectorAll('.alert-error');
89
- expect(errorElements.length).to.equal(0);
90
-
91
- await assertScreenshot('formfield/no-errors', getClip(formField));
92
- });
93
-
94
- it('renders in widget-only mode with errors', async () => {
95
- const formField: FormField = await fixture(html`
96
- <temba-field
97
- widget_only
98
- .errors=${['Widget only **error** with [link](https://example.com)']}
99
- >
100
- <input type="text" />
101
- </temba-field>
102
- `);
103
-
104
- await formField.updateComplete;
105
-
106
- // Check that error is rendered in widget-only mode
107
- const errorElements = formField.shadowRoot.querySelectorAll('.alert-error');
108
- expect(errorElements.length).to.equal(1);
109
-
110
- const errorElement = errorElements[0];
111
- const boldElement = errorElement.querySelector('strong');
112
- const linkElement = errorElement.querySelector('a');
113
- expect(boldElement).to.not.be.null;
114
- expect(linkElement).to.not.be.null;
115
-
116
- await assertScreenshot(
117
- 'formfield/widget-only-markdown-errors',
118
- getClip(formField)
119
- );
120
- });
121
- });