@cloudscape-design/components-themeable 3.0.375 → 3.0.377

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 (148) hide show
  1. package/lib/internal/manifest.json +1 -1
  2. package/lib/internal/scss/alert/styles.scss +27 -40
  3. package/lib/internal/scss/button-dropdown/styles.scss +4 -0
  4. package/lib/internal/scss/mixed-line-bar-chart/styles.scss +0 -5
  5. package/lib/internal/scss/table/sticky-scrollbar/styles.scss +3 -2
  6. package/lib/internal/template/alert/index.d.ts.map +1 -1
  7. package/lib/internal/template/alert/index.js +21 -16
  8. package/lib/internal/template/alert/index.js.map +1 -1
  9. package/lib/internal/template/alert/internal.d.ts.map +1 -1
  10. package/lib/internal/template/alert/internal.js +13 -14
  11. package/lib/internal/template/alert/internal.js.map +1 -1
  12. package/lib/internal/template/alert/styles.css.js +25 -25
  13. package/lib/internal/template/alert/styles.scoped.css +52 -66
  14. package/lib/internal/template/alert/styles.selectors.js +25 -25
  15. package/lib/internal/template/area-chart/model/use-chart-model.js +1 -1
  16. package/lib/internal/template/area-chart/model/use-chart-model.js.map +1 -1
  17. package/lib/internal/template/breadcrumb-group/internal.d.ts.map +1 -1
  18. package/lib/internal/template/breadcrumb-group/internal.js +5 -5
  19. package/lib/internal/template/breadcrumb-group/internal.js.map +1 -1
  20. package/lib/internal/template/button-dropdown/interfaces.d.ts +9 -1
  21. package/lib/internal/template/button-dropdown/interfaces.d.ts.map +1 -1
  22. package/lib/internal/template/button-dropdown/interfaces.js.map +1 -1
  23. package/lib/internal/template/button-dropdown/internal.d.ts.map +1 -1
  24. package/lib/internal/template/button-dropdown/internal.js +9 -2
  25. package/lib/internal/template/button-dropdown/internal.js.map +1 -1
  26. package/lib/internal/template/button-dropdown/styles.css.js +15 -14
  27. package/lib/internal/template/button-dropdown/styles.scoped.css +25 -21
  28. package/lib/internal/template/button-dropdown/styles.selectors.js +15 -14
  29. package/lib/internal/template/code-editor/index.d.ts.map +1 -1
  30. package/lib/internal/template/code-editor/index.js +26 -71
  31. package/lib/internal/template/code-editor/index.js.map +1 -1
  32. package/lib/internal/template/code-editor/listeners.d.ts +1 -1
  33. package/lib/internal/template/code-editor/listeners.d.ts.map +1 -1
  34. package/lib/internal/template/code-editor/listeners.js.map +1 -1
  35. package/lib/internal/template/code-editor/setup-editor.d.ts.map +1 -1
  36. package/lib/internal/template/code-editor/setup-editor.js +39 -36
  37. package/lib/internal/template/code-editor/setup-editor.js.map +1 -1
  38. package/lib/internal/template/code-editor/use-editor.d.ts +24 -0
  39. package/lib/internal/template/code-editor/use-editor.d.ts.map +1 -0
  40. package/lib/internal/template/code-editor/use-editor.js +71 -0
  41. package/lib/internal/template/code-editor/use-editor.js.map +1 -0
  42. package/lib/internal/template/form/index.d.ts.map +1 -1
  43. package/lib/internal/template/form/index.js +2 -1
  44. package/lib/internal/template/form/index.js.map +1 -1
  45. package/lib/internal/template/form-field/internal.d.ts.map +1 -1
  46. package/lib/internal/template/form-field/internal.js +17 -12
  47. package/lib/internal/template/form-field/internal.js.map +1 -1
  48. package/lib/internal/template/internal/analytics/components/analytics-funnel.d.ts +1 -1
  49. package/lib/internal/template/internal/analytics/components/analytics-funnel.d.ts.map +1 -1
  50. package/lib/internal/template/internal/analytics/components/analytics-funnel.js +92 -26
  51. package/lib/internal/template/internal/analytics/components/analytics-funnel.js.map +1 -1
  52. package/lib/internal/template/internal/analytics/context/analytics-context.d.ts +4 -0
  53. package/lib/internal/template/internal/analytics/context/analytics-context.d.ts.map +1 -1
  54. package/lib/internal/template/internal/analytics/context/analytics-context.js +4 -0
  55. package/lib/internal/template/internal/analytics/context/analytics-context.js.map +1 -1
  56. package/lib/internal/template/internal/analytics/hooks/use-funnel.d.ts +2 -0
  57. package/lib/internal/template/internal/analytics/hooks/use-funnel.d.ts.map +1 -1
  58. package/lib/internal/template/internal/components/chart-popover/index.d.ts.map +1 -1
  59. package/lib/internal/template/internal/components/chart-popover/index.js +1 -1
  60. package/lib/internal/template/internal/components/chart-popover/index.js.map +1 -1
  61. package/lib/internal/template/internal/components/menu-dropdown/index.d.ts +1 -1
  62. package/lib/internal/template/internal/components/menu-dropdown/index.d.ts.map +1 -1
  63. package/lib/internal/template/internal/components/menu-dropdown/index.js +7 -5
  64. package/lib/internal/template/internal/components/menu-dropdown/index.js.map +1 -1
  65. package/lib/internal/template/internal/components/menu-dropdown/interfaces.d.ts +1 -0
  66. package/lib/internal/template/internal/components/menu-dropdown/interfaces.d.ts.map +1 -1
  67. package/lib/internal/template/internal/components/menu-dropdown/interfaces.js.map +1 -1
  68. package/lib/internal/template/internal/environment.js +1 -1
  69. package/lib/internal/template/internal/environment.json +1 -1
  70. package/lib/internal/template/internal/plugins/api.d.ts +21 -25
  71. package/lib/internal/template/internal/plugins/api.d.ts.map +1 -1
  72. package/lib/internal/template/internal/plugins/api.js +15 -35
  73. package/lib/internal/template/internal/plugins/api.js.map +1 -1
  74. package/lib/internal/template/internal/plugins/controllers/action-buttons.d.ts +9 -0
  75. package/lib/internal/template/internal/plugins/controllers/action-buttons.d.ts.map +1 -1
  76. package/lib/internal/template/internal/plugins/controllers/action-buttons.js +11 -0
  77. package/lib/internal/template/internal/plugins/controllers/action-buttons.js.map +1 -1
  78. package/lib/internal/template/internal/plugins/controllers/drawers.d.ts +9 -0
  79. package/lib/internal/template/internal/plugins/controllers/drawers.d.ts.map +1 -1
  80. package/lib/internal/template/internal/plugins/controllers/drawers.js +11 -0
  81. package/lib/internal/template/internal/plugins/controllers/drawers.js.map +1 -1
  82. package/lib/internal/template/internal/utils/dom.d.ts +1 -8
  83. package/lib/internal/template/internal/utils/dom.d.ts.map +1 -1
  84. package/lib/internal/template/internal/utils/dom.js +1 -22
  85. package/lib/internal/template/internal/utils/dom.js.map +1 -1
  86. package/lib/internal/template/mixed-line-bar-chart/bar-series.d.ts.map +1 -1
  87. package/lib/internal/template/mixed-line-bar-chart/bar-series.js +14 -3
  88. package/lib/internal/template/mixed-line-bar-chart/bar-series.js.map +1 -1
  89. package/lib/internal/template/mixed-line-bar-chart/hooks/use-mouse-hover.js +1 -1
  90. package/lib/internal/template/mixed-line-bar-chart/hooks/use-mouse-hover.js.map +1 -1
  91. package/lib/internal/template/mixed-line-bar-chart/styles.css.js +11 -11
  92. package/lib/internal/template/mixed-line-bar-chart/styles.scoped.css +17 -22
  93. package/lib/internal/template/mixed-line-bar-chart/styles.selectors.js +11 -11
  94. package/lib/internal/template/modal/internal.d.ts.map +1 -1
  95. package/lib/internal/template/modal/internal.js +14 -12
  96. package/lib/internal/template/modal/internal.js.map +1 -1
  97. package/lib/internal/template/pie-chart/pie-chart.d.ts.map +1 -1
  98. package/lib/internal/template/pie-chart/pie-chart.js +1 -1
  99. package/lib/internal/template/pie-chart/pie-chart.js.map +1 -1
  100. package/lib/internal/template/popover/container.d.ts.map +1 -1
  101. package/lib/internal/template/popover/container.js +3 -2
  102. package/lib/internal/template/popover/container.js.map +1 -1
  103. package/lib/internal/template/progress-bar/index.d.ts.map +1 -1
  104. package/lib/internal/template/progress-bar/index.js +7 -4
  105. package/lib/internal/template/progress-bar/index.js.map +1 -1
  106. package/lib/internal/template/table/body-cell/td-element.d.ts +2 -1
  107. package/lib/internal/template/table/body-cell/td-element.d.ts.map +1 -1
  108. package/lib/internal/template/table/body-cell/td-element.js +3 -3
  109. package/lib/internal/template/table/body-cell/td-element.js.map +1 -1
  110. package/lib/internal/template/table/header-cell/index.d.ts +1 -1
  111. package/lib/internal/template/table/header-cell/index.d.ts.map +1 -1
  112. package/lib/internal/template/table/header-cell/index.js +2 -2
  113. package/lib/internal/template/table/header-cell/index.js.map +1 -1
  114. package/lib/internal/template/table/internal.d.ts.map +1 -1
  115. package/lib/internal/template/table/internal.js +12 -14
  116. package/lib/internal/template/table/internal.js.map +1 -1
  117. package/lib/internal/template/table/table-role/index.d.ts +3 -1
  118. package/lib/internal/template/table/table-role/index.d.ts.map +1 -1
  119. package/lib/internal/template/table/table-role/index.js +2 -1
  120. package/lib/internal/template/table/table-role/index.js.map +1 -1
  121. package/lib/internal/template/table/table-role/interfaces.d.ts +18 -0
  122. package/lib/internal/template/table/table-role/interfaces.d.ts.map +1 -0
  123. package/lib/internal/template/table/table-role/interfaces.js +4 -0
  124. package/lib/internal/template/table/table-role/interfaces.js.map +1 -0
  125. package/lib/internal/template/table/table-role/table-role-helper.d.ts +16 -4
  126. package/lib/internal/template/table/table-role/table-role-helper.d.ts.map +1 -1
  127. package/lib/internal/template/table/table-role/table-role-helper.js +39 -4
  128. package/lib/internal/template/table/table-role/table-role-helper.js.map +1 -1
  129. package/lib/internal/template/table/table-role/use-grid-navigation.d.ts +7 -0
  130. package/lib/internal/template/table/table-role/use-grid-navigation.d.ts.map +1 -0
  131. package/lib/internal/template/table/table-role/use-grid-navigation.js +185 -0
  132. package/lib/internal/template/table/table-role/use-grid-navigation.js.map +1 -0
  133. package/lib/internal/template/table/table-role/utils.d.ts +23 -0
  134. package/lib/internal/template/table/table-role/utils.d.ts.map +1 -0
  135. package/lib/internal/template/table/table-role/utils.js +141 -0
  136. package/lib/internal/template/table/table-role/utils.js.map +1 -0
  137. package/lib/internal/template/table/thead.d.ts.map +1 -1
  138. package/lib/internal/template/table/thead.js +4 -4
  139. package/lib/internal/template/table/thead.js.map +1 -1
  140. package/lib/internal/template/test-utils/dom/button-dropdown/index.js +1 -3
  141. package/lib/internal/template/test-utils/dom/button-dropdown/index.js.map +1 -1
  142. package/lib/internal/template/test-utils/selectors/button-dropdown/index.js +1 -3
  143. package/lib/internal/template/test-utils/selectors/button-dropdown/index.js.map +1 -1
  144. package/lib/internal/template/test-utils/tsconfig.tsbuildinfo +1 -1
  145. package/lib/internal/template/wizard/index.d.ts.map +1 -1
  146. package/lib/internal/template/wizard/index.js +8 -1
  147. package/lib/internal/template/wizard/index.js.map +1 -1
  148. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"listeners.js","sourceRoot":"lib/default/","sources":["code-editor/listeners.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGlC,OAAO,EAAE,sBAAsB,EAA6B,MAAM,oBAAoB,CAAC;AACvF,OAAO,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAC;AAC9E,OAAO,EAAE,iBAAiB,EAAE,MAAM,+CAA+C,CAAC;AAElF,MAAM,UAAU,eAAe,CAC7B,MAAmB,EACnB,QAAkE,EAClE,eAAyE;IAEzE,MAAM,sBAAsB,GAAG,mBAAmB,CAAC,CAAC,MAAoC,EAAE,EAAE;QAC1F,sBAAsB,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC;IAClD,CAAC,EAAE,CAAC,CAAC,CAAC;IACN,MAAM,YAAY,GAAG,iBAAiB,CAAC,GAAG,EAAE;QAC1C,MAAM,YAAY,GAAG,EAAE,KAAK,EAAE,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,QAAQ,EAAE,KAAI,EAAE,EAAE,CAAC;QACzD,sBAAsB,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;QAC/C,sBAAsB,CAAC,YAAY,CAAC,CAAC;IACvC,CAAC,CAAC,CAAC;IACH,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,MAAM,EAAE;YACX,OAAO;SACR;QAED,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;QAClC,OAAO,GAAG,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;IAClD,CAAC,EAAE,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC;AAC7B,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { useEffect } from 'react';\nimport { Ace } from 'ace-builds';\nimport { CodeEditorProps } from './interfaces';\nimport { fireNonCancelableEvent, NonCancelableEventHandler } from '../internal/events';\nimport { useDebounceCallback } from '../internal/hooks/use-debounce-callback';\nimport { useStableCallback } from '@cloudscape-design/component-toolkit/internal';\n\nexport function useChangeEffect(\n editor?: Ace.Editor,\n onChange?: NonCancelableEventHandler<CodeEditorProps.ChangeDetail>,\n onDelayedChange?: NonCancelableEventHandler<CodeEditorProps.ChangeDetail>\n) {\n const debouncedChangeHandler = useDebounceCallback((detail: CodeEditorProps.ChangeDetail) => {\n fireNonCancelableEvent(onDelayedChange, detail);\n }, 0);\n const handleChange = useStableCallback(() => {\n const changeDetail = { value: editor?.getValue() || '' };\n fireNonCancelableEvent(onChange, changeDetail);\n debouncedChangeHandler(changeDetail);\n });\n useEffect(() => {\n if (!editor) {\n return;\n }\n\n editor.on('change', handleChange);\n return () => editor.off('change', handleChange);\n }, [editor, handleChange]);\n}\n"]}
1
+ {"version":3,"file":"listeners.js","sourceRoot":"lib/default/","sources":["code-editor/listeners.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGlC,OAAO,EAAE,sBAAsB,EAA6B,MAAM,oBAAoB,CAAC;AACvF,OAAO,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAC;AAC9E,OAAO,EAAE,iBAAiB,EAAE,MAAM,+CAA+C,CAAC;AAElF,MAAM,UAAU,eAAe,CAC7B,MAAyB,EACzB,QAAkE,EAClE,eAAyE;IAEzE,MAAM,sBAAsB,GAAG,mBAAmB,CAAC,CAAC,MAAoC,EAAE,EAAE;QAC1F,sBAAsB,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC;IAClD,CAAC,EAAE,CAAC,CAAC,CAAC;IACN,MAAM,YAAY,GAAG,iBAAiB,CAAC,GAAG,EAAE;QAC1C,MAAM,YAAY,GAAG,EAAE,KAAK,EAAE,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,QAAQ,EAAE,KAAI,EAAE,EAAE,CAAC;QACzD,sBAAsB,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;QAC/C,sBAAsB,CAAC,YAAY,CAAC,CAAC;IACvC,CAAC,CAAC,CAAC;IACH,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,MAAM,EAAE;YACX,OAAO;SACR;QAED,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;QAClC,OAAO,GAAG,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;IAClD,CAAC,EAAE,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC;AAC7B,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { useEffect } from 'react';\nimport { Ace } from 'ace-builds';\nimport { CodeEditorProps } from './interfaces';\nimport { fireNonCancelableEvent, NonCancelableEventHandler } from '../internal/events';\nimport { useDebounceCallback } from '../internal/hooks/use-debounce-callback';\nimport { useStableCallback } from '@cloudscape-design/component-toolkit/internal';\n\nexport function useChangeEffect(\n editor: null | Ace.Editor,\n onChange?: NonCancelableEventHandler<CodeEditorProps.ChangeDetail>,\n onDelayedChange?: NonCancelableEventHandler<CodeEditorProps.ChangeDetail>\n) {\n const debouncedChangeHandler = useDebounceCallback((detail: CodeEditorProps.ChangeDetail) => {\n fireNonCancelableEvent(onDelayedChange, detail);\n }, 0);\n const handleChange = useStableCallback(() => {\n const changeDetail = { value: editor?.getValue() || '' };\n fireNonCancelableEvent(onChange, changeDetail);\n debouncedChangeHandler(changeDetail);\n });\n useEffect(() => {\n if (!editor) {\n return;\n }\n\n editor.on('change', handleChange);\n return () => editor.off('change', handleChange);\n }, [editor, handleChange]);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"setup-editor.d.ts","sourceRoot":"lib/default/","sources":["code-editor/setup-editor.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,GAAG,EAAE,MAA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Ac,CAAC,UAAU,CAAC,CAAC,QA8DhE"}
@@ -1,13 +1,6 @@
1
1
  import { supportsKeyboardAccessibility } from './util';
2
2
  export function setupEditor(ace, editor, setAnnotations, setCursorPosition, setHighlightedAnnotation, setPaneStatus) {
3
- ace.config.loadModule('ace/ext/language_tools', function () {
4
- editor.setOptions({
5
- displayIndentGuides: false,
6
- enableSnippets: true,
7
- enableBasicAutocompletion: true,
8
- });
9
- });
10
- editor.setAutoScrollEditorIntoView(true);
3
+ setEditorDefaults(ace, editor);
11
4
  // To display cursor position in status bar
12
5
  editor.session.selection.on('changeCursor', () => {
13
6
  setCursorPosition(editor.getCursorPosition());
@@ -20,28 +13,6 @@ export function setupEditor(ace, editor, setAnnotations, setCursorPosition, setH
20
13
  }
21
14
  setAnnotations(newAnnotations);
22
15
  });
23
- if (!supportsKeyboardAccessibility(ace)) {
24
- editor.commands.addCommand({
25
- name: 'exitCodeEditor',
26
- bindKey: 'Esc',
27
- exec: () => {
28
- editor.container.focus();
29
- },
30
- });
31
- }
32
- editor.on('focus', () => {
33
- editor.textInput.getElement().setAttribute('tabindex', 0);
34
- });
35
- editor.on('blur', () => {
36
- editor.textInput.getElement().setAttribute('tabindex', -1);
37
- });
38
- // prevent users to step into editor directly by keyboard
39
- editor.textInput.getElement().setAttribute('tabindex', -1);
40
- editor.commands.removeCommand('showSettingsMenu', false);
41
- // Prevent default behavior on error/warning icon click
42
- editor.on('guttermousedown', (e) => {
43
- e.stop();
44
- });
45
16
  const moveCursorToAnnotation = (a) => {
46
17
  if (typeof a.row === 'number') {
47
18
  editor.gotoLine(a.row + 1, a.column || 0, false);
@@ -78,6 +49,44 @@ export function setupEditor(ace, editor, setAnnotations, setCursorPosition, setH
78
49
  openAnnotation(row);
79
50
  }
80
51
  });
52
+ // HACK: Annotations aren't cleared when editor is empty.
53
+ editor.on('change', () => {
54
+ if (editor.getValue().length === 0) {
55
+ editor.session.clearAnnotations();
56
+ }
57
+ });
58
+ }
59
+ function setEditorDefaults(ace, editor) {
60
+ ace.config.loadModule('ace/ext/language_tools', function () {
61
+ editor.setOptions({
62
+ displayIndentGuides: false,
63
+ enableSnippets: true,
64
+ enableBasicAutocompletion: true,
65
+ });
66
+ });
67
+ editor.setAutoScrollEditorIntoView(true);
68
+ if (!supportsKeyboardAccessibility(ace)) {
69
+ editor.commands.addCommand({
70
+ name: 'exitCodeEditor',
71
+ bindKey: 'Esc',
72
+ exec: () => {
73
+ editor.container.focus();
74
+ },
75
+ });
76
+ }
77
+ editor.on('focus', () => {
78
+ editor.textInput.getElement().setAttribute('tabindex', 0);
79
+ });
80
+ editor.on('blur', () => {
81
+ editor.textInput.getElement().setAttribute('tabindex', -1);
82
+ });
83
+ // prevent users to step into editor directly by keyboard
84
+ editor.textInput.getElement().setAttribute('tabindex', -1);
85
+ editor.commands.removeCommand('showSettingsMenu', false);
86
+ // Prevent default behavior on error/warning icon click
87
+ editor.on('guttermousedown', (e) => {
88
+ e.stop();
89
+ });
81
90
  // HACK: Wrapped lines are highlighted individually. This is seriously the recommended fix.
82
91
  // See: https://github.com/ajaxorg/ace/issues/3067
83
92
  editor.setHighlightActiveLine(false);
@@ -109,12 +118,6 @@ export function setupEditor(ace, editor, setAnnotations, setCursorPosition, setH
109
118
  }
110
119
  };
111
120
  editor.setHighlightActiveLine(true);
112
- // HACK: Annotations aren't cleared when editor is empty.
113
- editor.on('change', () => {
114
- if (editor.getValue().length === 0) {
115
- editor.session.clearAnnotations();
116
- }
117
- });
118
121
  // HACK: "disable" error tooltips by hiding them as soon as they appear.
119
122
  // See https://github.com/ajaxorg/ace/issues/4004
120
123
  editor.on('showGutterTooltip', (tooltip) => {
@@ -1 +1 @@
1
- {"version":3,"file":"setup-editor.js","sourceRoot":"lib/default/","sources":["code-editor/setup-editor.ts"],"names":[],"mappings":"AAIA,OAAO,EAAc,6BAA6B,EAAE,MAAM,QAAQ,CAAC;AAEnE,MAAM,UAAU,WAAW,CACzB,GAAQ,EACR,MAAkB,EAClB,cAAsE,EAC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AAC,oBAAoB,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;YAC9C,OAAO,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;SACrC;IACH,CAAC,CAAC;IAEF,MAAM,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAC;IAEpC,yDAAyD;IACzD,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE;QACvB,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE;YAClC,MAAM,CAAC,OAAO,CAAC,gBAAgB,EAAE,CAAC;SACnC;IACH,CAAC,CAAC,CAAC;IAEH,wEAAwE;IACxE,iDAAiD;IACjD,MAAM,CAAC,EAAE,CAAC,mBAA0B,EAAE,CAAC,OAAY,EAAE,EAAE;QACrD,OAAO,CAAC,IAAI,EAAE,CAAC;IACjB,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React from 'react';\nimport { Ace } from 'ace-builds';\nimport { PaneStatus, supportsKeyboardAccessibility } from './util';\n\nexport function setupEditor(\n ace: any,\n editor: Ace.Editor,\n setAnnotations: React.Dispatch<React.SetStateAction<Ace.Annotation[]>>,\n setCursorPosition: React.Dispatch<React.SetStateAction<Ace.Point>>,\n setHighlightedAnnotation: React.Dispatch<React.SetStateAction<Ace.Annotation | undefined>>,\n setPaneStatus: React.Dispatch<React.SetStateAction<PaneStatus>>\n) {\n ace.config.loadModule('ace/ext/language_tools', function () {\n editor.setOptions({\n displayIndentGuides: false,\n enableSnippets: true,\n enableBasicAutocompletion: true,\n });\n });\n\n editor.setAutoScrollEditorIntoView(true);\n\n // To display cursor position in status bar\n editor.session.selection.on('changeCursor', () => {\n setCursorPosition(editor.getCursorPosition());\n });\n\n editor.session.on('changeAnnotation' as any, () => {\n const editorAnnotations = editor.session.getAnnotations();\n const newAnnotations = editorAnnotations.filter(a => a.type !== 'info');\n if (editorAnnotations.length !== newAnnotations.length) {\n editor.session.setAnnotations(newAnnotations);\n }\n setAnnotations(newAnnotations);\n });\n\n if (!supportsKeyboardAccessibility(ace)) {\n editor.commands.addCommand({\n name: 'exitCodeEditor',\n bindKey: 'Esc',\n exec: () => {\n editor.container.focus();\n },\n });\n }\n\n editor.on('focus', () => {\n (editor as any).textInput.getElement().setAttribute('tabindex', 0);\n });\n\n editor.on('blur', () => {\n (editor as any).textInput.getElement().setAttribute('tabindex', -1);\n });\n\n // prevent users to step into editor directly by keyboard\n (editor as any).textInput.getElement().setAttribute('tabindex', -1);\n\n editor.commands.removeCommand('showSettingsMenu', false);\n\n // Prevent default behavior on error/warning icon click\n editor.on('guttermousedown' as any, (e: any) => {\n e.stop();\n });\n\n const moveCursorToAnnotation = (a: Ace.Annotation) => {\n if (typeof a.row === 'number') {\n editor.gotoLine(a.row + 1, a.column || 0, false);\n }\n };\n\n const openAnnotation = (row: number) => {\n const currentAnnotations = editor.session.getAnnotations().filter(a => a.row === row && a.type !== 'info');\n const errors = currentAnnotations.filter(a => a.type === 'error');\n if (errors.length > 0) {\n setHighlightedAnnotation(errors[0]);\n setPaneStatus('error');\n moveCursorToAnnotation(errors[0]);\n } else if (currentAnnotations.length > 0) {\n setHighlightedAnnotation(currentAnnotations[0]);\n setPaneStatus('warning');\n moveCursorToAnnotation(currentAnnotations[0]);\n } else {\n setHighlightedAnnotation(undefined);\n setPaneStatus('hidden');\n editor.gotoLine(row + 1, 0, false);\n }\n };\n\n // open error/warning pane when user clicks on gutter icon\n editor.on('gutterclick' as any, (e: any) => {\n const { row }: Ace.Point = e.getDocumentPosition();\n openAnnotation(row);\n });\n\n // open error/warning pane when user presses space/enter on gutter icon\n editor.on('gutterkeydown', e => {\n if (e.isInAnnotationLane() && (e.getKey() === 'space' || e.getKey() === 'return')) {\n const row: number = e.getRow();\n openAnnotation(row);\n }\n });\n\n // HACK: Wrapped lines are highlighted individually. This is seriously the recommended fix.\n // See: https://github.com/ajaxorg/ace/issues/3067\n editor.setHighlightActiveLine(false);\n (editor as any).$updateHighlightActiveLine = function () {\n const session = this.getSession();\n\n let highlight;\n if (this.$highlightActiveLine) {\n if (this.$selectionStyle !== 'line' || !this.selection.isMultiLine()) {\n highlight = this.getCursorPosition();\n }\n if (this.renderer.$maxLines && this.session.getLength() === 1 && !(this.renderer.$minLines > 1)) {\n highlight = false;\n }\n }\n\n if (session.$highlightLineMarker && !highlight) {\n session.removeMarker(session.$highlightLineMarker.id);\n session.$highlightLineMarker = null;\n } else if (!session.$highlightLineMarker && highlight) {\n const range = new ace.Range(highlight.row, 0, highlight.row, Infinity);\n (range as any).id = session.addMarker(range, 'ace_active-line', 'fullLine');\n session.$highlightLineMarker = range;\n } else if (highlight) {\n session.$highlightLineMarker.start.row = highlight.row;\n session.$highlightLineMarker.end.row = highlight.row;\n session.$highlightLineMarker.start.column = 0;\n session._signal('changeBackMarker');\n }\n };\n\n editor.setHighlightActiveLine(true);\n\n // HACK: Annotations aren't cleared when editor is empty.\n editor.on('change', () => {\n if (editor.getValue().length === 0) {\n editor.session.clearAnnotations();\n }\n });\n\n // HACK: \"disable\" error tooltips by hiding them as soon as they appear.\n // See https://github.com/ajaxorg/ace/issues/4004\n editor.on('showGutterTooltip' as any, (tooltip: any) => {\n tooltip.hide();\n });\n}\n"]}
1
+ {"version":3,"file":"setup-editor.js","sourceRoot":"lib/default/","sources":["code-editor/setup-editor.ts"],"names":[],"mappings":"AAIA,OAAO,EAAc,6BAA6B,EAAE,MAAM,QAAQ,CAAC;AAEnE,MAAM,UAAU,WAAW,CACzB,GAAQ,EACR,MAAkB,EAClB,cAAsE,EACtE,iBAAkE,EAClE,wBAA0F,EAC1F,aAA+D;IAE/D,iBAAiB,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAE/B,2CAA2C;IAC3C,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC,cAAc,EAAE,GAAG,EAAE;QAC/C,iBAAiB,CAA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SAAS,CAAC,GAAG,CAAC;YACvD,OAAO,CAAC,oBAAoB,CAAC,GAAG,CAAC,GAAG,GAAG,SAAS,CAAC,GAAG,CAAC;YACrD,OAAO,CAAC,oBAAoB,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;YAC9C,OAAO,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;SACrC;IACH,CAAC,CAAC;IAEF,MAAM,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAC;IAEpC,wEAAwE;IACxE,iDAAiD;IACjD,MAAM,CAAC,EAAE,CAAC,mBAA0B,EAAE,CAAC,OAAY,EAAE,EAAE;QACrD,OAAO,CAAC,IAAI,EAAE,CAAC;IACjB,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React from 'react';\nimport { Ace } from 'ace-builds';\nimport { PaneStatus, supportsKeyboardAccessibility } from './util';\n\nexport function setupEditor(\n ace: any,\n editor: Ace.Editor,\n setAnnotations: React.Dispatch<React.SetStateAction<Ace.Annotation[]>>,\n setCursorPosition: React.Dispatch<React.SetStateAction<Ace.Point>>,\n setHighlightedAnnotation: React.Dispatch<React.SetStateAction<Ace.Annotation | undefined>>,\n setPaneStatus: React.Dispatch<React.SetStateAction<PaneStatus>>\n) {\n setEditorDefaults(ace, editor);\n\n // To display cursor position in status bar\n editor.session.selection.on('changeCursor', () => {\n setCursorPosition(editor.getCursorPosition());\n });\n\n editor.session.on('changeAnnotation' as any, () => {\n const editorAnnotations = editor.session.getAnnotations();\n const newAnnotations = editorAnnotations.filter(a => a.type !== 'info');\n if (editorAnnotations.length !== newAnnotations.length) {\n editor.session.setAnnotations(newAnnotations);\n }\n setAnnotations(newAnnotations);\n });\n\n const moveCursorToAnnotation = (a: Ace.Annotation) => {\n if (typeof a.row === 'number') {\n editor.gotoLine(a.row + 1, a.column || 0, false);\n }\n };\n\n const openAnnotation = (row: number) => {\n const currentAnnotations = editor.session.getAnnotations().filter(a => a.row === row && a.type !== 'info');\n const errors = currentAnnotations.filter(a => a.type === 'error');\n if (errors.length > 0) {\n setHighlightedAnnotation(errors[0]);\n setPaneStatus('error');\n moveCursorToAnnotation(errors[0]);\n } else if (currentAnnotations.length > 0) {\n setHighlightedAnnotation(currentAnnotations[0]);\n setPaneStatus('warning');\n moveCursorToAnnotation(currentAnnotations[0]);\n } else {\n setHighlightedAnnotation(undefined);\n setPaneStatus('hidden');\n editor.gotoLine(row + 1, 0, false);\n }\n };\n\n // open error/warning pane when user clicks on gutter icon\n editor.on('gutterclick' as any, (e: any) => {\n const { row }: Ace.Point = e.getDocumentPosition();\n openAnnotation(row);\n });\n\n // open error/warning pane when user presses space/enter on gutter icon\n editor.on('gutterkeydown', e => {\n if (e.isInAnnotationLane() && (e.getKey() === 'space' || e.getKey() === 'return')) {\n const row: number = e.getRow();\n openAnnotation(row);\n }\n });\n\n // HACK: Annotations aren't cleared when editor is empty.\n editor.on('change', () => {\n if (editor.getValue().length === 0) {\n editor.session.clearAnnotations();\n }\n });\n}\n\nfunction setEditorDefaults(ace: any, editor: Ace.Editor) {\n ace.config.loadModule('ace/ext/language_tools', function () {\n editor.setOptions({\n displayIndentGuides: false,\n enableSnippets: true,\n enableBasicAutocompletion: true,\n });\n });\n\n editor.setAutoScrollEditorIntoView(true);\n\n if (!supportsKeyboardAccessibility(ace)) {\n editor.commands.addCommand({\n name: 'exitCodeEditor',\n bindKey: 'Esc',\n exec: () => {\n editor.container.focus();\n },\n });\n }\n\n editor.on('focus', () => {\n (editor as any).textInput.getElement().setAttribute('tabindex', 0);\n });\n\n editor.on('blur', () => {\n (editor as any).textInput.getElement().setAttribute('tabindex', -1);\n });\n\n // prevent users to step into editor directly by keyboard\n (editor as any).textInput.getElement().setAttribute('tabindex', -1);\n\n editor.commands.removeCommand('showSettingsMenu', false);\n\n // Prevent default behavior on error/warning icon click\n editor.on('guttermousedown' as any, (e: any) => {\n e.stop();\n });\n\n // HACK: Wrapped lines are highlighted individually. This is seriously the recommended fix.\n // See: https://github.com/ajaxorg/ace/issues/3067\n editor.setHighlightActiveLine(false);\n (editor as any).$updateHighlightActiveLine = function () {\n const session = this.getSession();\n\n let highlight;\n if (this.$highlightActiveLine) {\n if (this.$selectionStyle !== 'line' || !this.selection.isMultiLine()) {\n highlight = this.getCursorPosition();\n }\n if (this.renderer.$maxLines && this.session.getLength() === 1 && !(this.renderer.$minLines > 1)) {\n highlight = false;\n }\n }\n\n if (session.$highlightLineMarker && !highlight) {\n session.removeMarker(session.$highlightLineMarker.id);\n session.$highlightLineMarker = null;\n } else if (!session.$highlightLineMarker && highlight) {\n const range = new ace.Range(highlight.row, 0, highlight.row, Infinity);\n (range as any).id = session.addMarker(range, 'ace_active-line', 'fullLine');\n session.$highlightLineMarker = range;\n } else if (highlight) {\n session.$highlightLineMarker.start.row = highlight.row;\n session.$highlightLineMarker.end.row = highlight.row;\n session.$highlightLineMarker.start.column = 0;\n session._signal('changeBackMarker');\n }\n };\n\n editor.setHighlightActiveLine(true);\n\n // HACK: \"disable\" error tooltips by hiding them as soon as they appear.\n // See https://github.com/ajaxorg/ace/issues/4004\n editor.on('showGutterTooltip' as any, (tooltip: any) => {\n tooltip.hide();\n });\n}\n"]}
@@ -0,0 +1,24 @@
1
+ /// <reference types="react" />
2
+ import { Ace } from 'ace-builds';
3
+ import { CodeEditorProps } from './interfaces';
4
+ export declare function useEditor(ace: any, loading?: boolean): {
5
+ editorRef: import("react").RefObject<HTMLDivElement>;
6
+ editor: Ace.Editor | null;
7
+ };
8
+ export declare function useSyncEditorLabels(editor: null | Ace.Editor, { controlId, ariaLabel, ariaLabelledby, ariaDescribedby, }: {
9
+ controlId?: string;
10
+ ariaLabel?: string;
11
+ ariaLabelledby?: string;
12
+ ariaDescribedby?: string;
13
+ }): void;
14
+ export declare function useSyncEditorSize(editor: null | Ace.Editor, { width, height }: {
15
+ width?: null | number;
16
+ height?: null | number;
17
+ }): {
18
+ onResize: () => void;
19
+ };
20
+ export declare function useSyncEditorValue(editor: null | Ace.Editor, value: string): void;
21
+ export declare function useSyncEditorLanguage(editor: null | Ace.Editor, language: string): void;
22
+ export declare function useSyncEditorWrapLines(editor: null | Ace.Editor, wrapLines?: boolean): void;
23
+ export declare function useSyncEditorTheme(editor: null | Ace.Editor, theme: CodeEditorProps.Theme): void;
24
+ //# sourceMappingURL=use-editor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-editor.d.ts","sourceRoot":"lib/default/","sources":["code-editor/use-editor.tsx"],"names":[],"mappings":";AAGA,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAGjC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C,wBAAgB,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,OAAO;;;EAmBpD;AAED,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,IAAI,GAAG,GAAG,CAAC,MAAM,EACzB,EACE,SAAS,EACT,SAAS,EACT,cAAc,EACd,eAAe,GAChB,EAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IAAC,eAAe,CAAC,EAAE,MAAM,CAAA;CAAE,QAiBjG;AAED,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,IAAI,GAAG,GAAG,CAAC,MAAM,EACzB,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;IAAE,KAAK,CAAC,EAAE,IAAI,GAAG,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,IAAI,GAAG,MAAM,CAAA;CAAE;;EAWrE;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,IAAI,GAAG,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,QAY1E;AAED,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,IAAI,GAAG,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,QAIhF;AAED,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,IAAI,GAAG,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,EAAE,OAAO,QAIpF;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,IAAI,GAAG,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,eAAe,CAAC,KAAK,QAIzF"}
@@ -0,0 +1,71 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { useCallback, useEffect, useRef, useState } from 'react';
4
+ import { getAceTheme, getDefaultConfig, getDefaultTheme } from './util';
5
+ export function useEditor(ace, loading) {
6
+ const editorRef = useRef(null);
7
+ const [editor, setEditor] = useState(null);
8
+ useEffect(() => {
9
+ const elem = editorRef.current;
10
+ if (!ace || !elem) {
11
+ return;
12
+ }
13
+ const config = getDefaultConfig(ace);
14
+ setEditor(ace.edit(elem, Object.assign(Object.assign({}, config), { theme: getAceTheme(getDefaultTheme(elem)) })));
15
+ }, [ace, loading]);
16
+ return { editorRef, editor };
17
+ }
18
+ export function useSyncEditorLabels(editor, { controlId, ariaLabel, ariaLabelledby, ariaDescribedby, }) {
19
+ useEffect(() => {
20
+ if (!editor) {
21
+ return;
22
+ }
23
+ const { textarea } = editor.renderer;
24
+ if (!textarea) {
25
+ return;
26
+ }
27
+ const updateAttribute = (attribute, value) => value ? textarea.setAttribute(attribute, value) : textarea.removeAttribute(attribute);
28
+ updateAttribute('id', controlId);
29
+ updateAttribute('aria-label', ariaLabel);
30
+ updateAttribute('aria-labelledby', ariaLabelledby);
31
+ updateAttribute('aria-describedby', ariaDescribedby);
32
+ }, [ariaLabel, ariaDescribedby, ariaLabelledby, controlId, editor]);
33
+ }
34
+ export function useSyncEditorSize(editor, { width, height }) {
35
+ useEffect(() => {
36
+ editor === null || editor === void 0 ? void 0 : editor.resize();
37
+ }, [editor, width, height]);
38
+ const onResize = useCallback(() => {
39
+ editor === null || editor === void 0 ? void 0 : editor.resize();
40
+ }, [editor]);
41
+ return { onResize };
42
+ }
43
+ export function useSyncEditorValue(editor, value) {
44
+ useEffect(() => {
45
+ if (!editor) {
46
+ return;
47
+ }
48
+ if (value === editor.getValue()) {
49
+ return;
50
+ }
51
+ const pos = editor.session.selection.toJSON();
52
+ editor.setValue(value, -1);
53
+ editor.session.selection.fromJSON(pos);
54
+ }, [editor, value]);
55
+ }
56
+ export function useSyncEditorLanguage(editor, language) {
57
+ useEffect(() => {
58
+ editor === null || editor === void 0 ? void 0 : editor.session.setMode(`ace/mode/${language}`);
59
+ }, [editor, language]);
60
+ }
61
+ export function useSyncEditorWrapLines(editor, wrapLines) {
62
+ useEffect(() => {
63
+ editor === null || editor === void 0 ? void 0 : editor.session.setUseWrapMode(wrapLines !== null && wrapLines !== void 0 ? wrapLines : true);
64
+ }, [editor, wrapLines]);
65
+ }
66
+ export function useSyncEditorTheme(editor, theme) {
67
+ useEffect(() => {
68
+ editor === null || editor === void 0 ? void 0 : editor.setTheme(getAceTheme(theme));
69
+ }, [editor, theme]);
70
+ }
71
+ //# sourceMappingURL=use-editor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-editor.js","sourceRoot":"lib/default/","sources":["code-editor/use-editor.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAGtC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAGxE,MAAM,UAAU,SAAS,CAAC,GAAQ,EAAE,OAAiB;IACnD,MAAM,SAAS,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAC;IAC/C,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAoB,IAAI,CAAC,CAAC;IAE9D,SAAS,CAAC,GAAG,EAAE;QAC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AS,CAAC,GAAG,EAAE;QACb,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,OAAO,CAAC,cAAc,CAAC,SAAS,aAAT,SAAS,cAAT,SAAS,GAAI,IAAI,CAAC,CAAC;IACpD,CAAC,EAAE,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;AAC1B,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,MAAyB,EAAE,KAA4B;IACxF,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,QAAQ,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC;IACvC,CAAC,EAAE,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;AACtB,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Ace } from 'ace-builds';\nimport { useCallback, useEffect, useRef, useState } from 'react';\nimport { getAceTheme, getDefaultConfig, getDefaultTheme } from './util';\nimport { CodeEditorProps } from './interfaces';\n\nexport function useEditor(ace: any, loading?: boolean) {\n const editorRef = useRef<HTMLDivElement>(null);\n const [editor, setEditor] = useState<null | Ace.Editor>(null);\n\n useEffect(() => {\n const elem = editorRef.current;\n if (!ace || !elem) {\n return;\n }\n const config = getDefaultConfig(ace);\n setEditor(\n ace.edit(elem, {\n ...config,\n theme: getAceTheme(getDefaultTheme(elem)),\n })\n );\n }, [ace, loading]);\n\n return { editorRef, editor };\n}\n\nexport function useSyncEditorLabels(\n editor: null | Ace.Editor,\n {\n controlId,\n ariaLabel,\n ariaLabelledby,\n ariaDescribedby,\n }: { controlId?: string; ariaLabel?: string; ariaLabelledby?: string; ariaDescribedby?: string }\n) {\n useEffect(() => {\n if (!editor) {\n return;\n }\n const { textarea } = editor.renderer as unknown as { textarea: HTMLTextAreaElement };\n if (!textarea) {\n return;\n }\n const updateAttribute = (attribute: string, value: string | undefined) =>\n value ? textarea.setAttribute(attribute, value) : textarea.removeAttribute(attribute);\n updateAttribute('id', controlId);\n updateAttribute('aria-label', ariaLabel);\n updateAttribute('aria-labelledby', ariaLabelledby);\n updateAttribute('aria-describedby', ariaDescribedby);\n }, [ariaLabel, ariaDescribedby, ariaLabelledby, controlId, editor]);\n}\n\nexport function useSyncEditorSize(\n editor: null | Ace.Editor,\n { width, height }: { width?: null | number; height?: null | number }\n) {\n useEffect(() => {\n editor?.resize();\n }, [editor, width, height]);\n\n const onResize = useCallback(() => {\n editor?.resize();\n }, [editor]);\n\n return { onResize };\n}\n\nexport function useSyncEditorValue(editor: null | Ace.Editor, value: string) {\n useEffect(() => {\n if (!editor) {\n return;\n }\n if (value === editor.getValue()) {\n return;\n }\n const pos = editor.session.selection.toJSON();\n editor.setValue(value, -1);\n editor.session.selection.fromJSON(pos);\n }, [editor, value]);\n}\n\nexport function useSyncEditorLanguage(editor: null | Ace.Editor, language: string) {\n useEffect(() => {\n editor?.session.setMode(`ace/mode/${language}`);\n }, [editor, language]);\n}\n\nexport function useSyncEditorWrapLines(editor: null | Ace.Editor, wrapLines?: boolean) {\n useEffect(() => {\n editor?.session.setUseWrapMode(wrapLines ?? true);\n }, [editor, wrapLines]);\n}\n\nexport function useSyncEditorTheme(editor: null | Ace.Editor, theme: CodeEditorProps.Theme) {\n useEffect(() => {\n editor?.setTheme(getAceTheme(theme));\n }, [editor, theme]);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"lib/default/","sources":["form/index.tsx"],"names":[],"mappings":";AAIA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AASzC,OAAO,EAAE,SAAS,EAAE,CAAC;AA4BrB,MAAM,CAAC,OAAO,UAAU,IAAI,CAAC,EAAE,OAAqB,EAAE,GAAG,KAAK,EAAE,EAAE,SAAS,eAU1E"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"lib/default/","sources":["form/index.tsx"],"names":[],"mappings":";AAIA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AASzC,OAAO,EAAE,SAAS,EAAE,CAAC;AAoBrB,MAAM,CAAC,OAAO,UAAU,IAAI,CAAC,EAAE,OAAqB,EAAE,GAAG,KAAK,EAAE,EAAE,SAAS,eAU1E"}
@@ -19,7 +19,8 @@ const FormWithAnalytics = (_a) => {
19
19
  funnelSubmit();
20
20
  }
21
21
  };
22
- return (React.createElement(InternalForm, Object.assign({ variant: variant, actions: actions && (React.createElement(ButtonContext.Provider, { value: { onClick: handleActionButtonClick } }, actions)) }, props, funnelProps, funnelStepProps)));
22
+ return (React.createElement(ButtonContext.Provider, { value: { onClick: handleActionButtonClick } },
23
+ React.createElement(InternalForm, Object.assign({ variant: variant, actions: actions }, props, funnelProps, funnelStepProps))));
23
24
  };
24
25
  export default function Form(_a) {
25
26
  var { variant = 'full-page' } = _a, props = __rest(_a, ["variant"]);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"lib/default/","sources":["form/index.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AAExE,OAAO,YAAY,MAAM,YAAY,CAAC;AACtC,OAAO,gBAAgB,MAAM,sCAAsC,CAAC;AAEpE,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,mDAAmD,CAAC;AACzG,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,EAAE,aAAa,EAAsB,MAAM,oCAAoC,CAAC;AACvF,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAC;AAIlF,MAAM,iBAAiB,GAAG,CAAC,EAAuD,EAAE,EAAE;QAA3D,EAAE,OAAO,GAAG,WAAW,EAAE,OAAO,OAAuB,EAAlB,KAAK,cAA1C,sBAA4C,CAAF;IACnE,MAAM,EAAE,WAAW,EAAE,YAAY,EAAE,yBAAyB,EAAE,GAAG,SAAS,EAAE,CAAC;IAC7E,MAAM,EAAE,eAAe,EAAE,GAAG,aAAa,EAAE,CAAC;IAE5C,MAAM,uBAAuB,GAAkC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE;QAC7E,IAAI,OAAO,KAAK,SAAS,EAAE;YACzB,yBAAyB,EAAE,CAAC;YAC5B,YAAY,EAAE,CAAC;SAChB;IACH,CAAC,CAAC;IAEF,OAAO,CACL,oBAAC,YAAY,kBACX,OAAO,EAAE,OAAO,EAChB,OAAO,EACL,OAAO,IAAI,CACT,oBAAC,aAAa,CAAC,QAAQ,IAAC,KAAK,EAAE,EAAE,OAAO,EAAE,uBAAuB,EAAE,IAAG,OAAO,CAA0B,CACxG,IAEC,KAAK,EACL,WAAW,EACX,eAAe,EACnB,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,IAAI,CAAC,EAA8C;QAA9C,EAAE,OAAO,GAAG,WAAW,OAAuB,EAAlB,KAAK,cAAjC,WAAmC,CAAF;IAC5D,MAAM,kBAAkB,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAEpD,OAAO,CACL,oBAAC,eAAe,IAAC,UAAU,EAAC,aAAa,EAAC,mBAAmB,EAAE,EAAE,EAAE,gBAAgB,EAAE,CAAC;QACpF,oBAAC,mBAAmB,IAAC,UAAU,EAAE,CAAC,EAAE,gBAAgB,EAAE,qBAAqB,EAAE;YAC3E,oBAAC,iBAAiB,kBAAC,OAAO,EAAE,OAAO,IAAM,KAAK,EAAM,kBAAkB,EAAI,CACtD,CACN,CACnB,CAAC;AACJ,CAAC;AAED,gBAAgB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React from 'react';\nimport { applyDisplayName } from '../internal/utils/apply-display-name';\nimport { FormProps } from './interfaces';\nimport InternalForm from './internal';\nimport useBaseComponent from '../internal/hooks/use-base-component';\n\nimport { AnalyticsFunnel, AnalyticsFunnelStep } from '../internal/analytics/components/analytics-funnel';\nimport { getFunnelNameSelector } from '../internal/analytics/selectors';\nimport { ButtonContext, ButtonContextProps } from '../internal/context/button-context';\nimport { useFunnel, useFunnelStep } from '../internal/analytics/hooks/use-funnel';\n\nexport { FormProps };\n\nconst FormWithAnalytics = ({ variant = 'full-page', actions, ...props }: FormProps) => {\n const { funnelProps, funnelSubmit, funnelNextOrSubmitAttempt } = useFunnel();\n const { funnelStepProps } = useFunnelStep();\n\n const handleActionButtonClick: ButtonContextProps['onClick'] = ({ variant }) => {\n if (variant === 'primary') {\n funnelNextOrSubmitAttempt();\n funnelSubmit();\n }\n };\n\n return (\n <InternalForm\n variant={variant}\n actions={\n actions && (\n <ButtonContext.Provider value={{ onClick: handleActionButtonClick }}>{actions}</ButtonContext.Provider>\n )\n }\n {...props}\n {...funnelProps}\n {...funnelStepProps}\n />\n );\n};\n\nexport default function Form({ variant = 'full-page', ...props }: FormProps) {\n const baseComponentProps = useBaseComponent('Form');\n\n return (\n <AnalyticsFunnel funnelType=\"single-page\" optionalStepNumbers={[]} totalFunnelSteps={1}>\n <AnalyticsFunnelStep stepNumber={1} stepNameSelector={getFunnelNameSelector()}>\n <FormWithAnalytics variant={variant} {...props} {...baseComponentProps} />\n </AnalyticsFunnelStep>\n </AnalyticsFunnel>\n );\n}\n\napplyDisplayName(Form, 'Form');\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"lib/default/","sources":["form/index.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AAExE,OAAO,YAAY,MAAM,YAAY,CAAC;AACtC,OAAO,gBAAgB,MAAM,sCAAsC,CAAC;AAEpE,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,mDAAmD,CA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AE;YAC3E,oBAAC,iBAAiB,kBAAC,OAAO,EAAE,OAAO,IAAM,KAAK,EAAM,kBAAkB,EAAI,CACtD,CACN,CACnB,CAAC;AACJ,CAAC;AAED,gBAAgB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React from 'react';\nimport { applyDisplayName } from '../internal/utils/apply-display-name';\nimport { FormProps } from './interfaces';\nimport InternalForm from './internal';\nimport useBaseComponent from '../internal/hooks/use-base-component';\n\nimport { AnalyticsFunnel, AnalyticsFunnelStep } from '../internal/analytics/components/analytics-funnel';\nimport { getFunnelNameSelector } from '../internal/analytics/selectors';\nimport { ButtonContext, ButtonContextProps } from '../internal/context/button-context';\nimport { useFunnel, useFunnelStep } from '../internal/analytics/hooks/use-funnel';\n\nexport { FormProps };\n\nconst FormWithAnalytics = ({ variant = 'full-page', actions, ...props }: FormProps) => {\n const { funnelProps, funnelSubmit, funnelNextOrSubmitAttempt } = useFunnel();\n const { funnelStepProps } = useFunnelStep();\n\n const handleActionButtonClick: ButtonContextProps['onClick'] = ({ variant }) => {\n if (variant === 'primary') {\n funnelNextOrSubmitAttempt();\n funnelSubmit();\n }\n };\n\n return (\n <ButtonContext.Provider value={{ onClick: handleActionButtonClick }}>\n <InternalForm variant={variant} actions={actions} {...props} {...funnelProps} {...funnelStepProps} />\n </ButtonContext.Provider>\n );\n};\n\nexport default function Form({ variant = 'full-page', ...props }: FormProps) {\n const baseComponentProps = useBaseComponent('Form');\n\n return (\n <AnalyticsFunnel funnelType=\"single-page\" optionalStepNumbers={[]} totalFunnelSteps={1}>\n <AnalyticsFunnelStep stepNumber={1} stepNameSelector={getFunnelNameSelector()}>\n <FormWithAnalytics variant={variant} {...props} {...baseComponentProps} />\n </AnalyticsFunnelStep>\n </AnalyticsFunnel>\n );\n}\n\napplyDisplayName(Form, 'Form');\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"internal.d.ts","sourceRoot":"lib/default/","sources":["form-field/internal.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAoB,MAAM,OAAO,CAAC;AAazC,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAetD,UAAU,mBAAmB;IAC3B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,wBAAgB,cAAc,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,kBAAkB,EAAE,EAAE,mBAAmB,eAiBvF;AAED,wBAAgB,cAAc,CAAC,EAC7B,EAAE,EACF,QAAQ,EACR,QAAQ,GACT,EAAE;IACD,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,OAAO,CAAC;IAClB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B,eAMA;AAED,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,EACxC,SAAS,EACT,OAAe,EACf,KAAK,EACL,IAAI,EACJ,WAAW,EACX,QAAQ,EACR,gBAAgB,EAChB,WAAW,EACX,cAAc,EACd,SAAS,EACT,WAAW,EACX,iBAAwB,EACxB,gBAAwB,EACxB,GAAG,IAAI,EACR,EAAE,sBAAsB,eA2HxB"}
1
+ {"version":3,"file":"internal.d.ts","sourceRoot":"lib/default/","sources":["form-field/internal.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAoB,MAAM,OAAO,CAAC;AAazC,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAetD,UAAU,mBAAmB;IAC3B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,wBAAgB,cAAc,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,kBAAkB,EAAE,EAAE,mBAAmB,eAiBvF;AAED,wBAAgB,cAAc,CAAC,EAC7B,EAAE,EACF,QAAQ,EACR,QAAQ,GACT,EAAE;IACD,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,OAAO,CAAC;IAClB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B,eAMA;AAED,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,EACxC,SAAS,EACT,OAAe,EACf,KAAK,EACL,IAAI,EACJ,WAAW,EACX,QAAQ,EACR,gBAAgB,EAChB,WAAW,EACX,cAAc,EACd,SAAS,EACT,WAAW,EACX,iBAAwB,EACxB,gBAAwB,EACxB,GAAG,IAAI,EACR,EAAE,sBAAsB,eAgIxB"}
@@ -52,22 +52,27 @@ export default function InternalFormField(_a) {
52
52
  [DATA_ATTR_FIELD_ERROR]: slotIds.error ? getFieldSlotSeletor(slotIds.error) : undefined,
53
53
  };
54
54
  useEffect(() => {
55
+ var _a, _b, _c;
55
56
  if (funnelInteractionId && errorText && funnelState.current !== 'complete') {
56
57
  const stepName = getNameFromSelector(stepNameSelector);
57
58
  const subStepName = getNameFromSelector(subStepNameSelector);
58
59
  errorCount.current++;
59
- FunnelMetrics.funnelSubStepError({
60
- funnelInteractionId,
61
- subStepSelector,
62
- subStepName,
63
- subStepNameSelector,
64
- stepNumber,
65
- stepName,
66
- stepNameSelector,
67
- fieldErrorSelector: getFieldSlotSeletor(slotIds.error),
68
- fieldLabelSelector: getFieldSlotSeletor(slotIds.label),
69
- subStepAllSelector: getSubStepAllSelector(),
70
- });
60
+ // We don't want to report an error if it is hidden, e.g. inside an Expandable Section.
61
+ const errorIsVisible = ((_c = (_b = (_a = __internalRootRef === null || __internalRootRef === void 0 ? void 0 : __internalRootRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect()) === null || _b === void 0 ? void 0 : _b.width) !== null && _c !== void 0 ? _c : 0) > 0;
62
+ if (errorIsVisible) {
63
+ FunnelMetrics.funnelSubStepError({
64
+ funnelInteractionId,
65
+ subStepSelector,
66
+ subStepName,
67
+ subStepNameSelector,
68
+ stepNumber,
69
+ stepName,
70
+ stepNameSelector,
71
+ fieldErrorSelector: getFieldSlotSeletor(slotIds.error),
72
+ fieldLabelSelector: getFieldSlotSeletor(slotIds.label),
73
+ subStepAllSelector: getSubStepAllSelector(),
74
+ });
75
+ }
71
76
  return () => {
72
77
  // eslint-disable-next-line react-hooks/exhaustive-deps
73
78
  errorCount.current--;
@@ -1 +1 @@
1
- {"version":3,"file":"internal.js","sourceRoot":"lib/default/","sources":["form-field/internal.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACzC,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,wCAAwC,CAAC;AAC/F,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAErE,OAAO,YAAY,MAAM,kBAAkB,CAAC;AAC5C,OAAO,YAAY,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAE3E,OAAO,MAAM,MAAM,iBAAiB,CAAC;AAErC,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,6CAA6C,CAAC;AAEnF,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAC;AACpG,OAAO,E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U,EAAE,QAAQ,EAAE,CAAC,CAAC,SAAS,IAC1D,cAAc,CACA,CAClB,CACG,CACP,CACG,CACP,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { useEffect } from 'react';\nimport clsx from 'clsx';\n\nimport { getBaseProps } from '../internal/base-component';\nimport { FormFieldContext, useFormFieldContext } from '../internal/context/form-field-context';\nimport { useUniqueId } from '../internal/hooks/use-unique-id';\nimport { useVisualRefresh } from '../internal/hooks/use-visual-mode';\n\nimport InternalGrid from '../grid/internal';\nimport InternalIcon from '../icon/internal';\nimport { getAriaDescribedBy, getGridDefinition, getSlotIds } from './util';\n\nimport styles from './styles.css.js';\nimport { InternalFormFieldProps } from './interfaces';\nimport { joinStrings } from '../internal/utils/strings';\nimport { useInternalI18n } from '../i18n/context';\nimport { InfoLinkLabelContext } from '../internal/context/info-link-label-context';\n\nimport { FunnelMetrics } from '../internal/analytics';\nimport { useFunnel, useFunnelStep, useFunnelSubStep } from '../internal/analytics/hooks/use-funnel';\nimport {\n DATA_ATTR_FIELD_ERROR,\n DATA_ATTR_FIELD_LABEL,\n getFieldSlotSeletor,\n getNameFromSelector,\n getSubStepAllSelector,\n} from '../internal/analytics/selectors';\n\ninterface FormFieldErrorProps {\n id?: string;\n children?: React.ReactNode;\n errorIconAriaLabel?: string;\n}\n\nexport function FormFieldError({ id, children, errorIconAriaLabel }: FormFieldErrorProps) {\n const i18n = useInternalI18n('form-field');\n\n return (\n <div id={id} className={styles.error}>\n <div className={styles['error-icon-shake-wrapper']}>\n <div\n role=\"img\"\n aria-label={i18n('i18nStrings.errorIconAriaLabel', errorIconAriaLabel)}\n className={styles['error-icon-scale-wrapper']}\n >\n <InternalIcon name=\"status-warning\" size=\"small\" />\n </div>\n </div>\n <span className={styles.error__message}>{children}</span>\n </div>\n );\n}\n\nexport function ConstraintText({\n id,\n hasError,\n children,\n}: {\n id?: string;\n hasError: boolean;\n children: React.ReactNode;\n}) {\n return (\n <div id={id} className={clsx(styles.constraint, hasError && styles['constraint-has-error'])}>\n {children}\n </div>\n );\n}\n\nexport default function InternalFormField({\n controlId,\n stretch = false,\n label,\n info,\n i18nStrings,\n children,\n secondaryControl,\n description,\n constraintText,\n errorText,\n __hideLabel,\n __internalRootRef = null,\n __disableGutters = false,\n ...rest\n}: InternalFormFieldProps) {\n const baseProps = getBaseProps(rest);\n const isRefresh = useVisualRefresh();\n\n const instanceUniqueId = useUniqueId('formField');\n const generatedControlId = controlId || instanceUniqueId;\n const formFieldId = controlId || generatedControlId;\n\n const { funnelInteractionId, submissionAttempt, funnelState, errorCount } = useFunnel();\n const { stepNumber, stepNameSelector } = useFunnelStep();\n const { subStepSelector, subStepNameSelector } = useFunnelSubStep();\n\n const slotIds = getSlotIds(formFieldId, label, description, constraintText, errorText);\n\n const ariaDescribedBy = getAriaDescribedBy(slotIds);\n\n const gridDefinition = getGridDefinition(stretch, !!secondaryControl, isRefresh);\n\n const {\n ariaLabelledby: parentAriaLabelledby,\n ariaDescribedby: parentAriaDescribedby,\n invalid: parentInvalid,\n } = useFormFieldContext({});\n\n const contextValuesWithoutControlId = {\n ariaLabelledby: joinStrings(parentAriaLabelledby, slotIds.label) || undefined,\n ariaDescribedby: joinStrings(parentAriaDescribedby, ariaDescribedBy) || undefined,\n invalid: !!errorText || !!parentInvalid,\n };\n\n const analyticsAttributes = {\n [DATA_ATTR_FIELD_LABEL]: slotIds.label ? getFieldSlotSeletor(slotIds.label) : undefined,\n [DATA_ATTR_FIELD_ERROR]: slotIds.error ? getFieldSlotSeletor(slotIds.error) : undefined,\n };\n\n useEffect(() => {\n if (funnelInteractionId && errorText && funnelState.current !== 'complete') {\n const stepName = getNameFromSelector(stepNameSelector);\n const subStepName = getNameFromSelector(subStepNameSelector);\n\n errorCount.current++;\n\n FunnelMetrics.funnelSubStepError({\n funnelInteractionId,\n subStepSelector,\n subStepName,\n subStepNameSelector,\n stepNumber,\n stepName,\n stepNameSelector,\n fieldErrorSelector: getFieldSlotSeletor(slotIds.error),\n fieldLabelSelector: getFieldSlotSeletor(slotIds.label),\n subStepAllSelector: getSubStepAllSelector(),\n });\n\n return () => {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n errorCount.current--;\n };\n }\n\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [funnelInteractionId, errorText, submissionAttempt, errorCount]);\n\n return (\n <div\n {...baseProps}\n className={clsx(baseProps.className, styles.root)}\n ref={__internalRootRef}\n {...analyticsAttributes}\n >\n <div className={clsx(__hideLabel && styles['visually-hidden'])}>\n {label && (\n <label className={styles.label} id={slotIds.label} htmlFor={generatedControlId}>\n {label}\n </label>\n )}\n <InfoLinkLabelContext.Provider value={slotIds.label}>\n {!__hideLabel && info && <span className={styles.info}>{info}</span>}\n </InfoLinkLabelContext.Provider>\n </div>\n\n {description && (\n <div className={styles.description} id={slotIds.description}>\n {description}\n </div>\n )}\n\n <div className={clsx(styles.controls, __hideLabel && styles['label-hidden'])}>\n <InternalGrid gridDefinition={gridDefinition} disableGutters={__disableGutters}>\n <FormFieldContext.Provider\n value={{\n controlId: generatedControlId,\n ...contextValuesWithoutControlId,\n }}\n >\n {children && <div className={styles.control}>{children}</div>}\n </FormFieldContext.Provider>\n\n {secondaryControl && (\n <FormFieldContext.Provider value={contextValuesWithoutControlId}>\n <div className={styles['secondary-control']}>{secondaryControl}</div>\n </FormFieldContext.Provider>\n )}\n </InternalGrid>\n </div>\n\n {(constraintText || errorText) && (\n <div className={styles.hints}>\n {errorText && (\n <FormFieldError id={slotIds.error} errorIconAriaLabel={i18nStrings?.errorIconAriaLabel}>\n {errorText}\n </FormFieldError>\n )}\n {constraintText && (\n <ConstraintText id={slotIds.constraint} hasError={!!errorText}>\n {constraintText}\n </ConstraintText>\n )}\n </div>\n )}\n </div>\n );\n}\n"]}
1
+ {"version":3,"file":"internal.js","sourceRoot":"lib/default/","sources":["form-field/internal.tsx"],"names":[],"mappings":";AAAA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2.0\nimport React, { useEffect } from 'react';\nimport clsx from 'clsx';\n\nimport { getBaseProps } from '../internal/base-component';\nimport { FormFieldContext, useFormFieldContext } from '../internal/context/form-field-context';\nimport { useUniqueId } from '../internal/hooks/use-unique-id';\nimport { useVisualRefresh } from '../internal/hooks/use-visual-mode';\n\nimport InternalGrid from '../grid/internal';\nimport InternalIcon from '../icon/internal';\nimport { getAriaDescribedBy, getGridDefinition, getSlotIds } from './util';\n\nimport styles from './styles.css.js';\nimport { InternalFormFieldProps } from './interfaces';\nimport { joinStrings } from '../internal/utils/strings';\nimport { useInternalI18n } from '../i18n/context';\nimport { InfoLinkLabelContext } from '../internal/context/info-link-label-context';\n\nimport { FunnelMetrics } from '../internal/analytics';\nimport { useFunnel, useFunnelStep, useFunnelSubStep } from '../internal/analytics/hooks/use-funnel';\nimport {\n DATA_ATTR_FIELD_ERROR,\n DATA_ATTR_FIELD_LABEL,\n getFieldSlotSeletor,\n getNameFromSelector,\n getSubStepAllSelector,\n} from '../internal/analytics/selectors';\n\ninterface FormFieldErrorProps {\n id?: string;\n children?: React.ReactNode;\n errorIconAriaLabel?: string;\n}\n\nexport function FormFieldError({ id, children, errorIconAriaLabel }: FormFieldErrorProps) {\n const i18n = useInternalI18n('form-field');\n\n return (\n <div id={id} className={styles.error}>\n <div className={styles['error-icon-shake-wrapper']}>\n <div\n role=\"img\"\n aria-label={i18n('i18nStrings.errorIconAriaLabel', errorIconAriaLabel)}\n className={styles['error-icon-scale-wrapper']}\n >\n <InternalIcon name=\"status-warning\" size=\"small\" />\n </div>\n </div>\n <span className={styles.error__message}>{children}</span>\n </div>\n );\n}\n\nexport function ConstraintText({\n id,\n hasError,\n children,\n}: {\n id?: string;\n hasError: boolean;\n children: React.ReactNode;\n}) {\n return (\n <div id={id} className={clsx(styles.constraint, hasError && styles['constraint-has-error'])}>\n {children}\n </div>\n );\n}\n\nexport default function InternalFormField({\n controlId,\n stretch = false,\n label,\n info,\n i18nStrings,\n children,\n secondaryControl,\n description,\n constraintText,\n errorText,\n __hideLabel,\n __internalRootRef = null,\n __disableGutters = false,\n ...rest\n}: InternalFormFieldProps) {\n const baseProps = getBaseProps(rest);\n const isRefresh = useVisualRefresh();\n\n const instanceUniqueId = useUniqueId('formField');\n const generatedControlId = controlId || instanceUniqueId;\n const formFieldId = controlId || generatedControlId;\n\n const { funnelInteractionId, submissionAttempt, funnelState, errorCount } = useFunnel();\n const { stepNumber, stepNameSelector } = useFunnelStep();\n const { subStepSelector, subStepNameSelector } = useFunnelSubStep();\n\n const slotIds = getSlotIds(formFieldId, label, description, constraintText, errorText);\n\n const ariaDescribedBy = getAriaDescribedBy(slotIds);\n\n const gridDefinition = getGridDefinition(stretch, !!secondaryControl, isRefresh);\n\n const {\n ariaLabelledby: parentAriaLabelledby,\n ariaDescribedby: parentAriaDescribedby,\n invalid: parentInvalid,\n } = useFormFieldContext({});\n\n const contextValuesWithoutControlId = {\n ariaLabelledby: joinStrings(parentAriaLabelledby, slotIds.label) || undefined,\n ariaDescribedby: joinStrings(parentAriaDescribedby, ariaDescribedBy) || undefined,\n invalid: !!errorText || !!parentInvalid,\n };\n\n const analyticsAttributes = {\n [DATA_ATTR_FIELD_LABEL]: slotIds.label ? getFieldSlotSeletor(slotIds.label) : undefined,\n [DATA_ATTR_FIELD_ERROR]: slotIds.error ? getFieldSlotSeletor(slotIds.error) : undefined,\n };\n\n useEffect(() => {\n if (funnelInteractionId && errorText && funnelState.current !== 'complete') {\n const stepName = getNameFromSelector(stepNameSelector);\n const subStepName = getNameFromSelector(subStepNameSelector);\n\n errorCount.current++;\n\n // We don't want to report an error if it is hidden, e.g. inside an Expandable Section.\n const errorIsVisible = (__internalRootRef?.current?.getBoundingClientRect()?.width ?? 0) > 0;\n\n if (errorIsVisible) {\n FunnelMetrics.funnelSubStepError({\n funnelInteractionId,\n subStepSelector,\n subStepName,\n subStepNameSelector,\n stepNumber,\n stepName,\n stepNameSelector,\n fieldErrorSelector: getFieldSlotSeletor(slotIds.error),\n fieldLabelSelector: getFieldSlotSeletor(slotIds.label),\n subStepAllSelector: getSubStepAllSelector(),\n });\n }\n\n return () => {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n errorCount.current--;\n };\n }\n\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [funnelInteractionId, errorText, submissionAttempt, errorCount]);\n\n return (\n <div\n {...baseProps}\n className={clsx(baseProps.className, styles.root)}\n ref={__internalRootRef}\n {...analyticsAttributes}\n >\n <div className={clsx(__hideLabel && styles['visually-hidden'])}>\n {label && (\n <label className={styles.label} id={slotIds.label} htmlFor={generatedControlId}>\n {label}\n </label>\n )}\n <InfoLinkLabelContext.Provider value={slotIds.label}>\n {!__hideLabel && info && <span className={styles.info}>{info}</span>}\n </InfoLinkLabelContext.Provider>\n </div>\n\n {description && (\n <div className={styles.description} id={slotIds.description}>\n {description}\n </div>\n )}\n\n <div className={clsx(styles.controls, __hideLabel && styles['label-hidden'])}>\n <InternalGrid gridDefinition={gridDefinition} disableGutters={__disableGutters}>\n <FormFieldContext.Provider\n value={{\n controlId: generatedControlId,\n ...contextValuesWithoutControlId,\n }}\n >\n {children && <div className={styles.control}>{children}</div>}\n </FormFieldContext.Provider>\n\n {secondaryControl && (\n <FormFieldContext.Provider value={contextValuesWithoutControlId}>\n <div className={styles['secondary-control']}>{secondaryControl}</div>\n </FormFieldContext.Provider>\n )}\n </InternalGrid>\n </div>\n\n {(constraintText || errorText) && (\n <div className={styles.hints}>\n {errorText && (\n <FormFieldError id={slotIds.error} errorIconAriaLabel={i18nStrings?.errorIconAriaLabel}>\n {errorText}\n </FormFieldError>\n )}\n {constraintText && (\n <ConstraintText id={slotIds.constraint} hasError={!!errorText}>\n {constraintText}\n </ConstraintText>\n )}\n </div>\n )}\n </div>\n );\n}\n"]}
@@ -5,7 +5,7 @@ export declare const FUNNEL_VERSION = "1.0";
5
5
  type AnalyticsFunnelProps = {
6
6
  children?: React.ReactNode;
7
7
  } & Pick<FunnelProps, 'funnelType' | 'optionalStepNumbers' | 'totalFunnelSteps'>;
8
- export declare const AnalyticsFunnel: ({ children, ...props }: AnalyticsFunnelProps) => JSX.Element;
8
+ export declare const AnalyticsFunnel: (props: AnalyticsFunnelProps) => JSX.Element;
9
9
  type AnalyticsFunnelStepProps = {
10
10
  children?: React.ReactNode | ((props: FunnelStepContextValue) => React.ReactNode);
11
11
  } & Pick<FunnelStepProps, 'stepNumber' | 'stepNameSelector'>;
@@ -1 +1 @@
1
- {"version":3,"file":"analytics-funnel.d.ts","sourceRoot":"lib/default/","sources":["internal/analytics/components/analytics-funnel.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAkD,MAAM,OAAO,CAAC;AAEvE,OAAO,EAKL,sBAAsB,EAGvB,MAAM,8BAA8B,CAAC;AAQtC,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAW7D,eAAO,MAAM,cAAc,QAAQ,CAAC;AAEpC,KAAK,oBAAoB,GAAG;IAAE,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;CAAE,GAAG,IAAI,CAC/D,WAAW,EACX,YAAY,GAAG,qBAAqB,GAAG,kBAAkB,CAC1D,CAAC;AAEF,eAAO,MAAM,eAAe,2BAA4B,oBAAoB,gBAoH3E,CAAC;AAEF,KAAK,wBAAwB,GAAG;IAC9B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,GAAG,CAAC,CAAC,KAAK,EAAE,sBAAsB,KAAK,KAAK,CAAC,SAAS,CAAC,CAAC;CACnF,GAAG,IAAI,CAAC,eAAe,EAAE,YAAY,GAAG,kBAAkB,CAAC,CAAC;AAE7D,eAAO,MAAM,mBAAmB,UAAW,wBAAwB,gBAMlE,CAAC;AAmDF,UAAU,2BAA2B;IACnC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAED,eAAO,MAAM,sBAAsB,iBAAkB,2BAA2B,gBAmF/E,CAAC"}
1
+ {"version":3,"file":"analytics-funnel.d.ts","sourceRoot":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