docks_theme_api 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (237) hide show
  1. checksums.yaml +15 -0
  2. data/.babelrc +4 -0
  3. data/.editorconfig +8 -0
  4. data/.eslintrc +115 -0
  5. data/.gitignore +24 -0
  6. data/.rubocop.yml +20 -0
  7. data/.travis.yml +16 -0
  8. data/Gemfile +4 -0
  9. data/README.md +5 -0
  10. data/Rakefile +3 -0
  11. data/assets/images/icons.svg +63 -0
  12. data/assets/scripts/coffeescript/pattern_library_helpers.coffee +8 -0
  13. data/assets/scripts/javascript/pattern_library_helpers.js +11 -0
  14. data/assets/scripts/pattern_library.js +10380 -0
  15. data/assets/scripts/pattern_library_demo.js +0 -0
  16. data/assets/styles/less/pattern-library-helpers.less +103 -0
  17. data/assets/styles/pattern-library-demo.css +1882 -0
  18. data/assets/styles/pattern-library.css +1882 -0
  19. data/assets/styles/sass/pattern-library-helpers.sass +90 -0
  20. data/assets/styles/scss/pattern-library-helpers.scss +99 -0
  21. data/assets/styles/stylus/pattern-library-helpers.styl +90 -0
  22. data/assets/templates/erb/demo.erb +26 -0
  23. data/assets/templates/erb/layouts/demo.erb +17 -0
  24. data/assets/templates/erb/layouts/pattern.erb +76 -0
  25. data/assets/templates/erb/partials/sidebar.erb +124 -0
  26. data/assets/templates/erb/partials/symbols/class.erb +1 -0
  27. data/assets/templates/erb/partials/symbols/demo.erb +40 -0
  28. data/assets/templates/erb/partials/symbols/factory.erb +70 -0
  29. data/assets/templates/erb/partials/symbols/function.erb +103 -0
  30. data/assets/templates/erb/partials/symbols/mixin.erb +62 -0
  31. data/assets/templates/erb/partials/symbols/variable.erb +59 -0
  32. data/assets/templates/erb/pattern.erb +102 -0
  33. data/assets/templates/haml/demo.haml +14 -0
  34. data/assets/templates/haml/layouts/demo.haml +6 -0
  35. data/assets/templates/haml/layouts/pattern.haml +38 -0
  36. data/assets/templates/haml/partials/sidebar.haml +68 -0
  37. data/assets/templates/haml/partials/symbols/class.haml +1 -0
  38. data/assets/templates/haml/partials/symbols/demo.haml +23 -0
  39. data/assets/templates/haml/partials/symbols/factory.haml +38 -0
  40. data/assets/templates/haml/partials/symbols/function.haml +54 -0
  41. data/assets/templates/haml/partials/symbols/mixin.haml +31 -0
  42. data/assets/templates/haml/partials/symbols/variable.haml +22 -0
  43. data/assets/templates/haml/pattern.haml +54 -0
  44. data/assets/templates/slim/demo.slim +24 -0
  45. data/assets/templates/slim/layouts/demo.slim +5 -0
  46. data/assets/templates/slim/layouts/pattern.slim +48 -0
  47. data/assets/templates/slim/partials/sidebar.slim +112 -0
  48. data/assets/templates/slim/partials/symbols/class.slim +1 -0
  49. data/assets/templates/slim/partials/symbols/demo.slim +30 -0
  50. data/assets/templates/slim/partials/symbols/factory.slim +57 -0
  51. data/assets/templates/slim/partials/symbols/function.slim +81 -0
  52. data/assets/templates/slim/partials/symbols/mixin.slim +45 -0
  53. data/assets/templates/slim/partials/symbols/variable.slim +35 -0
  54. data/assets/templates/slim/pattern.slim +63 -0
  55. data/docks_config.rb +32 -0
  56. data/docks_theme_api.gemspec +37 -0
  57. data/gulpfile.js +88 -0
  58. data/karma.conf.js +6 -0
  59. data/lib/docks_theme_api/components/base_component.rb +99 -0
  60. data/lib/docks_theme_api/components/code_block_component.rb +10 -0
  61. data/lib/docks_theme_api/components/popover_component.rb +15 -0
  62. data/lib/docks_theme_api/components/table_component.rb +34 -0
  63. data/lib/docks_theme_api/components/tablist_component.rb +11 -0
  64. data/lib/docks_theme_api/components.rb +21 -0
  65. data/lib/docks_theme_api/helpers/ui_helper.rb +69 -0
  66. data/lib/docks_theme_api/theme.rb +21 -0
  67. data/lib/docks_theme_api.rb +1 -0
  68. data/package.json +60 -0
  69. data/source/behaviors/filterable/filterable.coffee +353 -0
  70. data/source/behaviors/filterable/filterable.js +0 -0
  71. data/source/behaviors/filterable/filterable.scss +34 -0
  72. data/source/behaviors/filterable/package.json +3 -0
  73. data/source/behaviors/index.js +0 -0
  74. data/source/components/avatar/avatar.erb +20 -0
  75. data/source/components/avatar/avatar.js +142 -0
  76. data/source/components/avatar/avatar.scss +200 -0
  77. data/source/components/avatar/avatar_container.erb +13 -0
  78. data/source/components/avatar/package.json +3 -0
  79. data/source/components/avatar/spec/avatar_spec.js +81 -0
  80. data/source/components/badge/badge.scss +158 -0
  81. data/source/components/button/button.scss +213 -0
  82. data/source/components/card/card.scss +32 -0
  83. data/source/components/code_block/code-block.scss +353 -0
  84. data/source/components/code_block/code_block.erb +95 -0
  85. data/source/components/code_block/code_block.js +444 -0
  86. data/source/components/code_block/package.json +3 -0
  87. data/source/components/code_block/spec/code_block_spec.js +10 -0
  88. data/source/components/demo/demo.js +244 -0
  89. data/source/components/demo/demo.scss +90 -0
  90. data/source/components/demo/package.json +3 -0
  91. data/source/components/exploded/exploded.erb +25 -0
  92. data/source/components/exploded/exploded.js +694 -0
  93. data/source/components/exploded/exploded.scss +166 -0
  94. data/source/components/exploded/package.json +3 -0
  95. data/source/components/field/field.js +24 -0
  96. data/source/components/field/field.scss +101 -0
  97. data/source/components/field/package.json +3 -0
  98. data/source/components/header/header.scss +33 -0
  99. data/source/components/iframe/iframe.erb +12 -0
  100. data/source/components/iframe/iframe.js +381 -0
  101. data/source/components/iframe/package.json +3 -0
  102. data/source/components/index.js +37 -0
  103. data/source/components/inline_group/inline-group.scss +14 -0
  104. data/source/components/internal_link/internal_link.js +49 -0
  105. data/source/components/internal_link/package.json +3 -0
  106. data/source/components/list/list.scss +230 -0
  107. data/source/components/modal/modal.coffee +84 -0
  108. data/source/components/modal/modal.erb +19 -0
  109. data/source/components/modal/modal.js +0 -0
  110. data/source/components/modal/modal.scss +57 -0
  111. data/source/components/modal/package.json +3 -0
  112. data/source/components/notice/notice.scss +48 -0
  113. data/source/components/popover/package.json +3 -0
  114. data/source/components/popover/popover.coffee +562 -0
  115. data/source/components/popover/popover.erb +21 -0
  116. data/source/components/popover/popover.js +0 -0
  117. data/source/components/popover/popover.scss +139 -0
  118. data/source/components/range/range.scss +78 -0
  119. data/source/components/resizable/package.json +3 -0
  120. data/source/components/resizable/resizable.erb +30 -0
  121. data/source/components/resizable/resizable.js +250 -0
  122. data/source/components/resizable/resizable.scss +245 -0
  123. data/source/components/resizable/size_buttons.js +249 -0
  124. data/source/components/scroll_container/package.json +3 -0
  125. data/source/components/scroll_container/scroll-container.scss +4 -0
  126. data/source/components/scroll_container/scroll_container.js +24 -0
  127. data/source/components/section/section.scss +99 -0
  128. data/source/components/select/package.json +3 -0
  129. data/source/components/select/select.erb +21 -0
  130. data/source/components/select/select.js +35 -0
  131. data/source/components/select/select.scss +163 -0
  132. data/source/components/table/package.json +3 -0
  133. data/source/components/table/table.erb +16 -0
  134. data/source/components/table/table.js +351 -0
  135. data/source/components/table/table.scss +236 -0
  136. data/source/components/tablist/package.json +3 -0
  137. data/source/components/tablist/tablist.erb +13 -0
  138. data/source/components/tablist/tablist.js +246 -0
  139. data/source/components/tablist/tablist.scss +191 -0
  140. data/source/components/tablist/tablist_panel.erb +14 -0
  141. data/source/components/tablist/tablist_tab.erb +20 -0
  142. data/source/components/toggle/package.json +3 -0
  143. data/source/components/toggle/toggle.erb +11 -0
  144. data/source/components/toggle/toggle.js +211 -0
  145. data/source/components/toggle/toggle_container.erb +30 -0
  146. data/source/components/vertical_spacer/vertical-spacer.scss +3 -0
  147. data/source/components/vertical_stack/vertical-stack.scss +19 -0
  148. data/source/components/xray/package.json +3 -0
  149. data/source/components/xray/xray.erb +50 -0
  150. data/source/components/xray/xray.js +123 -0
  151. data/source/components/xray/xray.scss +79 -0
  152. data/source/foundation/app/app.js +15 -0
  153. data/source/foundation/app/package.json +3 -0
  154. data/source/pattern-library-demo.scss +13 -0
  155. data/source/pattern-library.scss +13 -0
  156. data/source/pattern_library.js +8 -0
  157. data/source/pattern_library_demo.js +8 -0
  158. data/source/structures/index.js +11 -0
  159. data/source/structures/sidebar/package.json +3 -0
  160. data/source/structures/sidebar/sidebar.js +69 -0
  161. data/source/structures/sidebar/sidebar.scss +79 -0
  162. data/source/utilities/builder/builder.js +138 -0
  163. data/source/utilities/builder/package.json +3 -0
  164. data/source/utilities/client/client.js +7 -0
  165. data/source/utilities/client/package.json +3 -0
  166. data/source/utilities/colors/colors.scss +112 -0
  167. data/source/utilities/defaults/defaults.scss +38 -0
  168. data/source/utilities/dom_cache/dom_cache.js +24 -0
  169. data/source/utilities/dom_cache/package.json +3 -0
  170. data/source/utilities/events/events.js +25 -0
  171. data/source/utilities/events/package.json +3 -0
  172. data/source/utilities/font_sizes/font-sizes.scss +85 -0
  173. data/source/utilities/foundation/a11y.scss +10 -0
  174. data/source/utilities/foundation/base.scss +29 -0
  175. data/source/utilities/foundation/icon.scss +114 -0
  176. data/source/utilities/foundation/layout.scss +67 -0
  177. data/source/utilities/foundation/page.scss +39 -0
  178. data/source/utilities/foundation/type.scss +208 -0
  179. data/source/utilities/functions/functions.scss +127 -0
  180. data/source/utilities/keycodes/keycodes.js +23 -0
  181. data/source/utilities/keycodes/package.json +3 -0
  182. data/source/utilities/markup/markup.js +90 -0
  183. data/source/utilities/markup/package.json +3 -0
  184. data/source/utilities/media/media.scss +172 -0
  185. data/source/utilities/mixins/mixins.scss +89 -0
  186. data/source/utilities/naming_convention/naming_convention.js +3 -0
  187. data/source/utilities/naming_convention/package.json +3 -0
  188. data/source/utilities/numbers/numbers.js +14 -0
  189. data/source/utilities/numbers/package.json +3 -0
  190. data/source/utilities/painting/package.json +3 -0
  191. data/source/utilities/painting/painting.js +7 -0
  192. data/source/utilities/pattern/package.json +3 -0
  193. data/source/utilities/pattern/pattern.js +50 -0
  194. data/source/utilities/query_string/package.json +3 -0
  195. data/source/utilities/query_string/query_string.js +24 -0
  196. data/source/utilities/template/package.json +3 -0
  197. data/source/utilities/template/template.js +10 -0
  198. data/source/utilities/text_range/package.json +3 -0
  199. data/source/utilities/text_range/text_range.js +30 -0
  200. data/source/utilities/ui_events/package.json +3 -0
  201. data/source/utilities/ui_events/ui_events.js +85 -0
  202. data/source/utilities/variables/variables.scss +18 -0
  203. data/source/utilities/z_indexes/z-indexes.scss +88 -0
  204. data/source/vendor/array_includes.js +28 -0
  205. data/source/vendor/highlight.js +1142 -0
  206. data/source/vendor/index.js +1 -0
  207. data/source/vendor/matrix.js +399 -0
  208. data/source/vendor/query_string.js +66 -0
  209. data/spec/assets/.eslintrc +9 -0
  210. data/spec/assets/spec_fixture.js +33 -0
  211. data/spec/assets/spec_helper.js +19 -0
  212. data/spec/lib/components/base_component_spec.rb +156 -0
  213. data/spec/lib/components_spec.rb +30 -0
  214. data/spec/lib/helpers/ui_helper_spec.rb +62 -0
  215. data/spec/lib/theme_spec.rb +25 -0
  216. data/spec/spec_helper.rb +15 -0
  217. data/tasks/gulp/.eslintrc +6 -0
  218. data/tasks/gulp/browser_sync.js +8 -0
  219. data/tasks/gulp/code_quality/scripts.js +10 -0
  220. data/tasks/gulp/config/index.js +116 -0
  221. data/tasks/gulp/minify/scripts.js +13 -0
  222. data/tasks/gulp/minify/styles.js +13 -0
  223. data/tasks/gulp/pattern_library/index.js +5 -0
  224. data/tasks/gulp/pattern_library/scripts.js +10 -0
  225. data/tasks/gulp/pattern_library/styles.js +10 -0
  226. data/tasks/gulp/scripts.js +8 -0
  227. data/tasks/gulp/spec/scripts.js +11 -0
  228. data/tasks/gulp/styles.js +17 -0
  229. data/tasks/gulp/utilities/babel/relative_require.js +22 -0
  230. data/tasks/gulp/utilities/babel/spec_helper.js +20 -0
  231. data/tasks/gulp/utilities/browserify_bundler.js +22 -0
  232. data/tasks/gulp/utilities/handle_errors.js +13 -0
  233. data/tasks/gulp/watch.js +9 -0
  234. data/tasks/rake/rspec.rake +7 -0
  235. data/tasks/rake/rubocop.rake +8 -0
  236. data/tasks/rake/templates.rake +50 -0
  237. metadata +470 -0
@@ -0,0 +1,139 @@
1
+ /*============================================================================
2
+ Next Popover
3
+ ==============================================================================*/
4
+
5
+ $popover-tooltip-size: rem(10);
6
+ $popover-max-width: rem(400);
7
+ $popover-min-width: rem(150);
8
+ $popover-max-width-percent: 100%;
9
+ $popover-max-height: rem(800);
10
+ $popover-vertical-margin: half(default(spacing)) + ($popover-tooltip-size / 2);
11
+ $popover-background-color: color(white);
12
+ $popover-section-border: 1px solid color(gray-light);
13
+ $popover-box-shadow: 0 0 0 1px rgba(color(slate), 0.05), 0 2px 7px 1px rgba(color(slate), 0.16);
14
+
15
+
16
+
17
+ .popover__container {
18
+ position: relative;
19
+ display: inline-flex;
20
+ @include z-index(popover-resting, page);
21
+
22
+ > *:focus { outline: 0; }
23
+ }
24
+
25
+ .popover__container--contains-active-popover {
26
+ @include z-index(popover-active, page);
27
+ }
28
+
29
+ .popover__container--is-deactivating {
30
+ @include z-index(popover-deactivating, page);
31
+ }
32
+
33
+ .popover__container--full-width {
34
+ display: flex;
35
+ }
36
+
37
+
38
+
39
+ .popover {
40
+ position: absolute;
41
+ left: 0;
42
+ top: 100%;
43
+
44
+ transform: scale(0);
45
+ display: inline-block;
46
+ max-width: $popover-max-width-percent;
47
+ margin: $popover-vertical-margin default(spacing);
48
+
49
+ background-color: $popover-background-color;
50
+ border-radius: default(border-radius);
51
+ opacity: 0;
52
+ box-shadow: $popover-box-shadow;
53
+
54
+ transition: transform 0.35s cubic-bezier(.27,1.41,.53,.97), opacity 0.2s ease;
55
+ }
56
+
57
+ .popover--is-active {
58
+ transform: scale(1);
59
+ opacity: 1;
60
+ }
61
+
62
+ .popover--is-positioned-above {
63
+ top: auto;
64
+ bottom: 100%;
65
+
66
+ .popover__tooltip {
67
+ top: 100%;
68
+
69
+ &:after { top: $popover-tooltip-size / -2; }
70
+ }
71
+ }
72
+
73
+
74
+ .popover__tooltip {
75
+ position: absolute;
76
+ left: 50%;
77
+ top: (-2 * $popover-tooltip-size);
78
+
79
+ width: ($popover-tooltip-size * 2);
80
+ height: ($popover-tooltip-size * 2);
81
+ margin-left: ($popover-tooltip-size * -1);
82
+ overflow: hidden;
83
+
84
+ &:after {
85
+ content: "";
86
+
87
+ position: absolute;
88
+ top: ($popover-tooltip-size * 3 / 2);
89
+ left: 50%;
90
+ transform: rotate(45deg);
91
+
92
+ margin-left: ($popover-tooltip-size / -2);
93
+
94
+ display: block;
95
+ height: $popover-tooltip-size;
96
+ width: $popover-tooltip-size;
97
+
98
+ background-color: $popover-background-color;
99
+ box-shadow: $popover-box-shadow;
100
+ }
101
+ }
102
+
103
+
104
+
105
+ .popover__content-wrapper {
106
+ display: flex;
107
+ max-width: $popover-max-width;
108
+ max-height: $popover-max-height;
109
+ border-radius: default(border-radius);
110
+ overflow: hidden;
111
+ }
112
+
113
+
114
+
115
+ .popover__content {
116
+ flex: 0 0 auto;
117
+ display: inline-flex;
118
+ flex-direction: column;
119
+ max-height: 100%;
120
+ min-width: $popover-min-width;
121
+
122
+ > *:first-child {
123
+ margin-top: 0;
124
+ }
125
+
126
+ > *:last-child {
127
+ margin-bottom: 0;
128
+ }
129
+ }
130
+
131
+
132
+
133
+
134
+ .popover__pane {
135
+ flex: 0 1 auto;
136
+ overflow: auto;
137
+ -webkit-overflow-scrolling: touch;
138
+ max-width: 100%;
139
+ }
@@ -0,0 +1,78 @@
1
+ // ___ _____ ___ ___
2
+ // / /\ ___ / /::\ / /\ / /\
3
+ // / /:/_ / /\ / /:/\:\ / /:/_ / /::\
4
+ // / /:/ /\ ___ ___ / /:/ / /:/ \:\ / /:/ /\ / /:/\:\
5
+ // / /:/ /::\/__/\ / /\/__/::\ /__/:/ \__\:|/ /:/ /:/_ / /:/~/:/
6
+ // /__/:/ /:/\:\ \:\ / /:/\__\/\:\_\ \:\ / /:/__/:/ /:/ /\/__/:/ /:/___
7
+ // \ \:\/:/~/:/\ \:\ /:/ \ \:\/\ \:\ /:/\ \:\/:/ /:/\ \:\/:::::/
8
+ // \ \::/ /:/ \ \:\/:/ \__\::/\ \:\/:/ \ \::/ /:/ \ \::/~~~~
9
+ // \__\/ /:/ \ \::/ /__/:/ \ \::/ \ \:\/:/ \ \:\
10
+ // /__/:/ \__\/ \__\/ \__\/ \ \::/ \ \:\
11
+ // \__\/ \__\/ \__\/
12
+
13
+ //*
14
+ // @pattern Slider
15
+ //
16
+ // A simple range slider. Use this component for situations where the user has
17
+ // to select from a continuous range of values with a minimum and maximum. For
18
+ // example, this component is used to change the perspective and pane gap for
19
+ // the `Exploded` component.
20
+ //
21
+ // @since 1.0.0
22
+
23
+ //*
24
+ // @markup
25
+ // <label class="label" for="range">Try something in range</label>
26
+ // <input class="range" name="range" id="range" type="range">
27
+
28
+ .range {
29
+ width: 100%;
30
+ margin: 0;
31
+
32
+ -webkit-appearance: none;
33
+ appearance: none;
34
+ background-color: transparent;
35
+
36
+ &:focus {
37
+ outline: none;
38
+ }
39
+ }
40
+
41
+ $range__track--size: default(control-size--large);
42
+ $range__thumb--spacing: (0.1 * default(control-size--large));
43
+ $range__thumb--size: ($range__track--size - double($range__thumb--spacing));
44
+
45
+ @mixin range__track {
46
+ // box model
47
+ width: 100%;
48
+ height: $range__track--size;
49
+
50
+ // backdrop
51
+ cursor: pointer;
52
+ background-color: ui-color(gray, dark);
53
+ border-radius: half($range__track--size);
54
+ padding: $range__thumb--spacing;
55
+ }
56
+
57
+ @mixin range__thumb {
58
+ // box model
59
+ height: $range__thumb--size;
60
+ width: $range__thumb--size;
61
+
62
+ // backdrop
63
+ box-shadow: 1px 1px 3px rgba(color(black), 0.15);
64
+ border-radius: half($range__thumb--size);
65
+ background: ui-color(gray, light);
66
+ cursor: pointer;
67
+ -webkit-appearance: none;
68
+ appearance: none;
69
+ }
70
+
71
+ .range::-webkit-slider-runnable-track { @include range__track; }
72
+ .range:focus::-webkit-slider-runnable-track { outline: none; }
73
+ .range::-moz-range-track { @include range__track; }
74
+ .range::-ms-track { @include range__track; }
75
+
76
+ .range::-webkit-slider-thumb { @include range__thumb; }
77
+ .range::-moz-range-thumb { @include range__thumb; }
78
+ .range::-ms-thumb { @include range__thumb; }
@@ -0,0 +1,3 @@
1
+ {
2
+ "main": "resizable.js"
3
+ }
@@ -0,0 +1,30 @@
1
+ <%
2
+ resizable.configure { |config| config.defaults(id: unique_iframe_id) }
3
+ id = resizable.id
4
+ %>
5
+
6
+ <div class="resizable" data-iframe-id="<%= id %>">
7
+ <div class="resizable__actions">
8
+ <div class="resizable__width-indicator">
9
+ <span class="resizable__width-indicator__px"></span>px / <span class="resizable__width-indicator__em"></span>em
10
+ </div>
11
+
12
+ <div class="resizable__size-buttons">
13
+ <% %w(small medium large full).each_with_index do |size, index| %>
14
+ <div class="resizable__size-button resizable__size-button--<%= size %>" role="button" tabindex="<%= index == 0 ? '0' : '-1' %>" data-resizable-size-button-size="<%= size %>">
15
+ <span class="helper--visually-hidden">Set the resizable demo window to size: <%= size %>.</span>
16
+ <%= docks_icon(size) %>
17
+ </div>
18
+ <% end %>
19
+ </div>
20
+ </div>
21
+
22
+ <div class="card">
23
+
24
+ <%= docks_iframe id: id, demo: resizable.demo %>
25
+
26
+ <div class="resizable__handle" tabindex="0">
27
+ <span class="helper--visually-hidden">Use the arrow keys to resize the resizable demo window.</span>
28
+ </div>
29
+ </div>
30
+ </div>
@@ -0,0 +1,250 @@
1
+ import SizeButtons from "./size_buttons";
2
+
3
+ import { Communicator } from "~components/iframe";
4
+ import Events from "~utilities/events";
5
+ import UIEvents from "~utilities/ui_events";
6
+ import Keycodes from "~utilities/keycodes";
7
+ import Builder from "~utilities/builder";
8
+
9
+ const classes = {
10
+ root: "resizable",
11
+ handle: "resizable__handle",
12
+ container: "resizable__size-button",
13
+ width_indicator: "resizable__width-indicator",
14
+ px_indicator: "resizable__width-indicator__px",
15
+ em_indicator: "resizable__width-indicator__em"
16
+ };
17
+
18
+ const states = {
19
+ root: { transitioning: "resizable--is-transitioning-width" },
20
+ size_button: {
21
+ hidden: "resizable__size-button--is-hidden",
22
+ active: "resizable__size-button--is-active"
23
+ },
24
+ width_indicator: { visible: "resizable__width-indicator--is-visible" }
25
+ };
26
+
27
+ const SHOW_WIDTH_DURATION = 2500;
28
+
29
+ var Resizable,
30
+ key_on_handle, handle_drag_move, start_dragging_handle;
31
+
32
+ //*
33
+ // Handles key presses on the resizable handle. If the key is an arrow key,
34
+ // the resizable component will be resized appropriately. If the shift key is
35
+ // being pressed at the same time, the resizing will be accelerated.
36
+ //
37
+ // @param {Object} event - The `keypress` event.
38
+ // @private
39
+
40
+ key_on_handle = (event) => {
41
+ var width_change;
42
+
43
+ if(!Keycodes.ARROWS.includes(event.which)) { return; }
44
+ event.preventDefault();
45
+
46
+ width_change = event.shiftKey ? 10 : 2;
47
+ if([Keycodes.LEFT, Keycodes.DOWN].includes(event.which)) {
48
+ width_change = width_change * -1;
49
+ }
50
+
51
+ Resizable.for(event.target).set_width({ delta: width_change });
52
+ };
53
+
54
+ //*
55
+ // Handles a drag movement while holding onto a resizable handle. As the user
56
+ // drags, the associated resizable component will resize.
57
+ //
58
+ // @param {Object} context - The context for the current drag.
59
+ // @param {Object} event - The `mousemove`/ `touchmove` event.
60
+ //
61
+ // @private
62
+
63
+ handle_drag_move = (context, event) => {
64
+ var x = UIEvents.coordinates(event).x,
65
+ delta = x - context.start_x;
66
+
67
+ event.preventDefault();
68
+ context.set_width(context.start_width + 2 * delta);
69
+ };
70
+
71
+ //*
72
+ // Initializes the required events/ attributes to perform a drag on a resizable
73
+ // handle. This function also removes all pointer events on the resizable to
74
+ // prevent unnecessary clicks/ hovers/ selects.
75
+ //
76
+ // @param {Object} context - The context for the current drag.
77
+
78
+ start_dragging_handle = (context) => {
79
+ var drag_move, drag_end, listeners;
80
+
81
+ context.iframe.style.pointerEvents = "none";
82
+
83
+ drag_move = (event) => { handle_drag_move(context, event); };
84
+ drag_end = () => {
85
+ listeners.remove();
86
+ context.iframe.style.pointerEvents = null;
87
+ };
88
+
89
+ listeners = UIEvents.add_drag_listeners(drag_move, drag_end);
90
+ };
91
+
92
+ //*
93
+ // The constructor around a `Resizable` component. This component manages many
94
+ // things, including: the intialization of resizing by dragging on the
95
+ // `Resizable`'s handle, responding to changes in the viewport size, and
96
+ // responding to changes in the height of the contained `iframe`.
97
+ //
98
+ // @param {HTMLElement} node - The root node for the `Resizable`
99
+ //
100
+ // @factory
101
+
102
+ Resizable = (root) => {
103
+ var api,
104
+ structure, set_width, show_width, size_buttons, handle_host_resize,
105
+ min_width, max_width, container_side_padding, width_taken_by_side_components,
106
+ communicator, respond_to_height, set_height, initialize_handle_resize,
107
+ container_styles;
108
+
109
+ size_buttons = SizeButtons.within(root)[0];
110
+
111
+ communicator = Communicator();
112
+ communicator.register.from_node(root);
113
+
114
+ respond_to_height = (event) => { set_height(event.height); };
115
+ communicator.on(Events.types.height_change, respond_to_height);
116
+ communicator.on(Events.types.height_request, respond_to_height);
117
+
118
+ structure = {
119
+ root,
120
+ iframe: root.querySelector("iframe"),
121
+ handle: root.querySelector(`.${classes.handle}`),
122
+ container: root.parentNode,
123
+ width_indicator: root.querySelector(`.${classes.width_indicator}`)
124
+ };
125
+
126
+ container_styles = window.getComputedStyle(structure.container);
127
+ container_side_padding = parseInt(container_styles.paddingLeft, 10) + parseInt(container_styles.paddingRight, 10);
128
+
129
+ width_taken_by_side_components = structure.handle.offsetWidth;
130
+ max_width = structure.iframe.offsetWidth;
131
+ min_width = parseInt(window.getComputedStyle(root).minWidth, 10) - width_taken_by_side_components;
132
+
133
+ //*
134
+ // Checks whether or not a resize of the viewport has caused the resizable
135
+ // width to be greater than it is allowed to be. If so, it will deactivate
136
+ // the size button that caused that width to be active (if applicable), and
137
+ // will resize the `Resizable` and display the width.
138
+ //
139
+ // @param {Object} event - The `resize` event on the `window`.
140
+ // @private
141
+
142
+ handle_host_resize = () => {
143
+ max_width = structure.container.offsetWidth - container_side_padding - width_taken_by_side_components;
144
+ show_width();
145
+ };
146
+
147
+ //*
148
+ // Sets the height of the `Resizable`. This is done directly on the contained
149
+ // `iframe`.
150
+ //
151
+ // @param {Number} height - The new height of the contained `iframe`.
152
+ // @private
153
+
154
+ set_height = (height) => {
155
+ structure.iframe.style.height = `${height}px`;
156
+ };
157
+
158
+ //*
159
+ // Shows the current width of the contained `iframe`. This involves a few
160
+ // things: the width is converted to `em` and both the `px` and `em` widths
161
+ // are displayed in the width indicator, the visible state is added to the
162
+ // width indicator, and a timeout is set up to remove the visible state (so
163
+ // that the indicator is hidden after a small delay).
164
+ //
165
+ // @param {Number} width (iframe.offsetWidth) - The width to display.
166
+ // @private
167
+
168
+ show_width = (() => {
169
+ var show_width_timeout;
170
+
171
+ return () => {
172
+ var width = structure.iframe.offsetWidth;
173
+
174
+ structure.width_indicator.querySelector(`.${classes.px_indicator}`).textContent = width;
175
+ structure.width_indicator.querySelector(`.${classes.em_indicator}`).textContent = (width / 16).toFixed(2);
176
+
177
+ if(show_width_timeout) {
178
+ clearTimeout(show_width_timeout);
179
+ } else {
180
+ structure.width_indicator.classList.add(states.width_indicator.visible);
181
+ }
182
+
183
+ show_width_timeout = setTimeout(() => {
184
+ structure.width_indicator.classList.remove(states.width_indicator.visible);
185
+ show_width_timeout = null;
186
+ }, SHOW_WIDTH_DURATION);
187
+ };
188
+ })();
189
+
190
+ set_width = (width, options = {}) => {
191
+ if(typeof width === "object") {
192
+ options = width;
193
+ width = root.offsetWidth - width_taken_by_side_components + (options.delta || 0);
194
+ }
195
+
196
+ if(options.animated) {
197
+ root.classList.add(states.root.transitioning);
198
+ UIEvents.transition(root, () => { root.classList.remove(states.root.transitioning); });
199
+ }
200
+
201
+ if(width) {
202
+ width = Math.max(Math.min(width, max_width), min_width);
203
+ root.style.width = `${width + width_taken_by_side_components}px`;
204
+ } else {
205
+ root.style.width = null;
206
+ }
207
+
208
+ show_width();
209
+
210
+ size_buttons.try_size(width);
211
+ return width;
212
+ };
213
+
214
+ //*
215
+ // Listens for the start of a drag on the `Resizable` component's handle and
216
+ // passes the associated context to `start_dragging_handle` so that the drag
217
+ // events can be properly attached.
218
+ //
219
+ // @param {Object} event - The `mousedown`/ `touchstart` event.
220
+ // @private
221
+
222
+ initialize_handle_resize = (event) => {
223
+ var context = {
224
+ start_x: UIEvents.coordinates(event).x,
225
+ start_width: structure.iframe.offsetWidth,
226
+ max_width: structure.container.offsetWidth - container_side_padding,
227
+ set_width: set_width,
228
+ iframe: structure.iframe
229
+ };
230
+
231
+ start_dragging_handle(context);
232
+ };
233
+
234
+ show_width();
235
+
236
+ $(window).on("resize", handle_host_resize);
237
+ $(structure.handle).on(UIEvents.drag.start, initialize_handle_resize);
238
+
239
+ api = { set_width };
240
+ return api;
241
+ };
242
+
243
+ Resizable.init = () => {
244
+ SizeButtons.init();
245
+ Builder.build_and_cache(Resizable, { name: classes.root });
246
+
247
+ $(document).on("keydown", `.${classes.handle}`, key_on_handle);
248
+ };
249
+
250
+ export default Resizable;