katalyst-kpop 3.4.0 → 4.0.0.beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +92 -74
  3. data/app/assets/builds/katalyst/kpop.esm.js +463 -457
  4. data/app/assets/builds/katalyst/kpop.js +463 -457
  5. data/app/assets/builds/katalyst/kpop.min.js +1 -1
  6. data/app/assets/builds/katalyst/kpop.min.js.map +1 -1
  7. data/app/assets/stylesheets/katalyst/kpop.css +69 -0
  8. data/app/components/kpop/frame_component.html.erb +3 -14
  9. data/app/components/kpop/frame_component.rb +15 -11
  10. data/app/components/kpop/modal_component.html.erb +7 -6
  11. data/app/components/kpop/modal_component.rb +12 -31
  12. data/app/controllers/concerns/katalyst/kpop/frame_request.rb +67 -8
  13. data/app/javascript/kpop/application.js +68 -7
  14. data/app/javascript/kpop/controllers/frame_controller.js +96 -66
  15. data/app/javascript/kpop/modals/content_modal.js +2 -58
  16. data/app/javascript/kpop/modals/frame_modal.js +19 -76
  17. data/app/javascript/kpop/modals/modal.js +96 -49
  18. data/app/javascript/kpop/modals/stream_modal.js +11 -62
  19. data/app/javascript/kpop/utils/debug.js +22 -0
  20. data/app/javascript/kpop/utils/link_observer.js +151 -0
  21. data/app/javascript/kpop/utils/ruleset.js +43 -0
  22. data/app/javascript/kpop/utils/stream_actions.js +21 -0
  23. data/app/views/layouts/kpop/frame.html.erb +3 -1
  24. data/app/views/layouts/kpop/stream.html.erb +3 -0
  25. data/lib/katalyst/kpop/engine.rb +1 -8
  26. data/lib/katalyst/kpop/matchers/modal_matcher.rb +1 -1
  27. data/lib/katalyst/kpop/matchers/src_matcher.rb +33 -0
  28. data/lib/katalyst/kpop/matchers.rb +11 -40
  29. metadata +8 -19
  30. data/app/assets/stylesheets/katalyst/kpop/_frame.scss +0 -90
  31. data/app/assets/stylesheets/katalyst/kpop/_modal.scss +0 -88
  32. data/app/assets/stylesheets/katalyst/kpop/_scrim.scss +0 -46
  33. data/app/assets/stylesheets/katalyst/kpop/_side_panel.scss +0 -64
  34. data/app/assets/stylesheets/katalyst/kpop/_variables.scss +0 -24
  35. data/app/assets/stylesheets/katalyst/kpop.scss +0 -6
  36. data/app/components/kpop/modal/footer_component.rb +0 -21
  37. data/app/components/kpop/modal/header_component.rb +0 -21
  38. data/app/components/kpop/modal/title_component.html.erb +0 -6
  39. data/app/components/kpop/modal/title_component.rb +0 -28
  40. data/app/components/scrim_component.rb +0 -32
  41. data/app/helpers/kpop_helper.rb +0 -32
  42. data/app/javascript/kpop/controllers/modal_controller.js +0 -30
  43. data/app/javascript/kpop/controllers/scrim_controller.js +0 -159
  44. data/app/javascript/kpop/debug.js +0 -3
  45. data/app/javascript/kpop/turbo_actions.js +0 -46
  46. data/app/javascript/kpop/utils/stream_renderer.js +0 -15
  47. data/lib/katalyst/kpop/turbo.rb +0 -49
@@ -1,159 +0,0 @@
1
- import { Controller } from "@hotwired/stimulus";
2
-
3
- import DEBUG from "../debug";
4
-
5
- /**
6
- * Scrim controller wraps an element that creates a whole page layer.
7
- * It is intended to be used behind a modal or nav drawer.
8
- *
9
- * If the Scrim element receives a click event, it automatically triggers "scrim:hide".
10
- *
11
- * You can show and hide the scrim programmatically by calling show/hide on the controller, e.g. using an outlet.
12
- *
13
- * If you need to respond to the scrim showing or hiding you should subscribe to "scrim:show" and "scrim:hide".
14
- */
15
- export default class ScrimController extends Controller {
16
- static values = {
17
- open: Boolean,
18
- captive: Boolean,
19
- zIndex: Number,
20
- };
21
-
22
- connect() {
23
- if (DEBUG) console.debug("scrim:connect");
24
-
25
- this.defaultZIndexValue = this.zIndexValue;
26
- this.defaultCaptiveValue = this.captiveValue;
27
-
28
- this.element.scrim = this;
29
- }
30
-
31
- disconnect() {
32
- if (DEBUG) console.debug("scrim:disconnect");
33
-
34
- delete this.element.scrim;
35
- }
36
-
37
- async show({
38
- captive = this.defaultCaptiveValue,
39
- zIndex = this.defaultZIndexValue,
40
- top = window.scrollY,
41
- animate = true,
42
- } = {}) {
43
- if (DEBUG) console.debug("scrim:before-show");
44
-
45
- // hide the scrim before opening the new one if it's already open
46
- if (this.openValue) {
47
- await this.hide({ animate });
48
- }
49
-
50
- // update internal state
51
- this.openValue = true;
52
-
53
- // notify listeners of pending request
54
- this.dispatch("show", { bubbles: true });
55
-
56
- if (DEBUG) console.debug("scrim:show-start");
57
-
58
- // update state, perform style updates
59
- this.#show(captive, zIndex, top);
60
-
61
- if (animate) {
62
- // animate opening
63
- // this will trigger an animationEnd event via CSS that completes the open
64
- this.element.dataset.showAnimating = "";
65
-
66
- await new Promise((resolve) => {
67
- this.element.addEventListener("animationend", () => resolve(), {
68
- once: true,
69
- });
70
- });
71
-
72
- delete this.element.dataset.showAnimating;
73
- }
74
-
75
- if (DEBUG) console.debug("scrim:show-end");
76
- }
77
-
78
- async hide({ animate = true } = {}) {
79
- if (!this.openValue || this.element.dataset.hideAnimating) return;
80
-
81
- if (DEBUG) console.debug("scrim:before-hide");
82
-
83
- // notify listeners of pending request
84
- this.dispatch("hide", { bubbles: true });
85
-
86
- if (DEBUG) console.debug("scrim:hide-start");
87
-
88
- if (animate) {
89
- // set animation state
90
- // this will trigger an animationEnd event via CSS that completes the hide
91
- this.element.dataset.hideAnimating = "";
92
-
93
- await new Promise((resolve) => {
94
- this.element.addEventListener("animationend", () => resolve(), {
95
- once: true,
96
- });
97
- });
98
-
99
- delete this.element.dataset.hideAnimating;
100
- }
101
-
102
- this.#hide();
103
-
104
- this.openValue = false;
105
-
106
- if (DEBUG) console.debug("scrim:hide-end");
107
- }
108
-
109
- dismiss(event) {
110
- if (DEBUG) console.debug("scrim:dismiss");
111
-
112
- if (!this.captiveValue) this.dispatch("dismiss", { bubbles: true });
113
- }
114
-
115
- escape(event) {
116
- if (
117
- event.key === "Escape" &&
118
- !this.captiveValue &&
119
- !event.defaultPrevented
120
- ) {
121
- this.dispatch("dismiss", { bubbles: true });
122
- }
123
- }
124
-
125
- /**
126
- * Clips body to viewport size and sets the z-index
127
- */
128
- #show(captive, zIndex, top) {
129
- this.captiveValue = captive;
130
- this.zIndexValue = zIndex;
131
- this.scrollY = top;
132
-
133
- this.element.style.zIndex = this.zIndexValue;
134
- document.body.style.top = `-${top}px`;
135
- document.body.style.position = "fixed";
136
- document.body.style.paddingRight = `-${this.scrollPadding}px`;
137
-
138
- if (document.body.scrollHeight > window.innerHeight) {
139
- document.body.style.overflowY = "scroll";
140
- }
141
- }
142
-
143
- /**
144
- * Unclips body from viewport size and unsets the z-index
145
- */
146
- #hide() {
147
- this.captiveValue = this.defaultCaptiveValue;
148
- this.zIndexValue = this.defaultZIndexValue;
149
-
150
- this.element.style.removeProperty("z-index");
151
- document.body.style.removeProperty("position");
152
- document.body.style.removeProperty("top");
153
- document.body.style.removeProperty("overflow-y");
154
-
155
- window.scrollTo({ left: 0, top: this.scrollY, behavior: "instant" });
156
-
157
- delete this.scrollY;
158
- }
159
- }
@@ -1,3 +0,0 @@
1
- const DEBUG = false;
2
-
3
- export default DEBUG;
@@ -1,46 +0,0 @@
1
- import { Turbo } from "@hotwired/turbo-rails";
2
-
3
- import DEBUG from "./debug";
4
-
5
- import { StreamModal } from "./modals/stream_modal";
6
- import { StreamRenderer } from "./utils/stream_renderer";
7
-
8
- function kpop(action) {
9
- return action.targetElements[0]?.kpop;
10
- }
11
-
12
- Turbo.StreamActions.kpop_open = function () {
13
- const animate = !kpop(this).openValue;
14
-
15
- kpop(this)
16
- ?.dismiss({ animate, reason: "before-turbo-stream" })
17
- .then(() => {
18
- new StreamRenderer(this.targetElements[0], this).render();
19
- kpop(this)?.open(new StreamModal(this.target, this), { animate });
20
- });
21
- };
22
-
23
- Turbo.StreamActions.kpop_dismiss = function () {
24
- kpop(this)?.dismiss({ reason: "turbo_stream.kpop.dismiss" });
25
- };
26
-
27
- Turbo.StreamActions.kpop_redirect_to = function () {
28
- if (this.dataset.turboFrame === this.target) {
29
- if (DEBUG)
30
- console.debug(
31
- `kpop: redirecting ${this.target} to ${this.getAttribute("href")}`,
32
- );
33
- const a = document.createElement("A");
34
- a.setAttribute("data-turbo-action", "replace");
35
- this.targetElements[0].delegate.linkClickIntercepted(
36
- a,
37
- this.getAttribute("href"),
38
- );
39
- } else {
40
- if (DEBUG)
41
- console.debug(`kpop: redirecting to ${this.getAttribute("href")}`);
42
- Turbo.visit(this.getAttribute("href"), {
43
- action: this.dataset.turboAction,
44
- });
45
- }
46
- };
@@ -1,15 +0,0 @@
1
- import DEBUG from "../debug";
2
-
3
- export class StreamRenderer {
4
- constructor(frame, action) {
5
- this.frame = frame;
6
- this.action = action;
7
- }
8
-
9
- render() {
10
- if (DEBUG) console.debug("stream-renderer:render");
11
- this.frame.src = "";
12
- this.frame.innerHTML = "";
13
- this.frame.append(this.action.templateContent);
14
- }
15
- }
@@ -1,49 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Katalyst
4
- module Kpop
5
- module Turbo
6
- class TagBuilder
7
- delegate :action, :turbo_stream_action_tag, to: :@builder
8
-
9
- def initialize(builder)
10
- @builder = builder
11
- end
12
-
13
- # Open a modal in the kpop frame identified by <tt>id</tt> either the <tt>content</tt> passed in or a
14
- # rendering result determined by the <tt>rendering</tt> keyword arguments, the content in the block,
15
- # or the rendering of the content as a record. Examples:
16
- #
17
- # <%= turbo_stream.kpop.open modal %>
18
- # <%= turbo_stream.kpop.open partial: "modals/modal", locals: { record: } %>
19
- # <%= turbo_stream.kpop.open do %>
20
- # <%= render Kpop::ModalComponent.new(title: "Example") do %>
21
- # ...
22
- # <% end %>
23
- # <% end %>
24
- def open(content = nil, id: "kpop", **, &)
25
- action(:kpop_open, id, content, **, &)
26
- end
27
-
28
- # Render a turbo stream action that will dismiss any open kpop modal.
29
- def dismiss(id: "kpop")
30
- turbo_stream_action_tag(:kpop_dismiss, target: id)
31
- end
32
-
33
- # Renders a kpop redirect controller response that will escape the frame and navigate to the given URL.
34
- # Note: turbo does not currently snapshot page history accurately when using "advance" (Oct 23).
35
- def redirect_to(href, id: "kpop", action: "replace", target: nil)
36
- turbo_stream_action_tag(
37
- :kpop_redirect_to,
38
- target: id,
39
- href:,
40
- data: {
41
- turbo_action: action,
42
- turbo_frame: target,
43
- },
44
- )
45
- end
46
- end
47
- end
48
- end
49
- end