shimmer 0.0.18 → 0.0.19

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: de8e99f1e252a60ee4c57442fe9fe67ba7af78e626b55d7c1756eedf3a83e404
4
- data.tar.gz: d28eeba9b1cdf8d9c1fc46151a334dc0993cacfbafe91223f14647e988a3ba23
3
+ metadata.gz: adda5b02ed66f485505f07b24ba314621c5b0dd1cae9ce3093681651f0a1a509
4
+ data.tar.gz: 89c1baa878afdf2bb38c2cc62eeafd298f15916f11466e5ec1e31eb5b42f9be6
5
5
  SHA512:
6
- metadata.gz: e750c73c60fa769a97526a0eaeb13b0f497539d9ae5c5500c581e2b0aafa7dc922c61b6edf6c4514d8946e8526d5789b5e454ce5787f4850cb598bd9450c6f05
7
- data.tar.gz: 62bcf6a9014420997d088bd41e9c491b4257456ec75f5881e252db5b7aea8b107c2d531ff2b10cba44e037d8eeb387a0edfbedcc09618da898dd3267bf84cad2
6
+ metadata.gz: f2add223e56adabf705dcb3061950ea47613d50caf4b7c240b3c7aa1907dbb0ef52b179b409183d2d205f21789d3cc15719e0ade1ba17387085eb47f9e2945d1
7
+ data.tar.gz: e496ccb035f571cd070c2af88968d0ab6d9d45bcf23016655a9a7213beccf9c83907f001f2f26c4188ce5ce1bc4affbd5c29d2b16d43d60a7949df0e9446f908
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Shimmer
4
+ class ConsentSettings
5
+ SETTINGS = [:essential, :targeting, :statistic].freeze
6
+ DEFAULT = [:essential].freeze
7
+
8
+ SETTINGS.each do |setting|
9
+ attr_accessor setting
10
+ alias_method "#{setting}?", setting
11
+ end
12
+
13
+ def initialize(cookies)
14
+ @cookies = cookies
15
+ allowed = @cookies[:consent].to_s.split(",").map(&:strip)
16
+ SETTINGS.each do |setting|
17
+ instance_variable_set "@#{setting}", DEFAULT.include?(setting) || allowed.include?(setting.to_s)
18
+ end
19
+ end
20
+
21
+ def save
22
+ value = SETTINGS.map { |e| e.to_s if instance_variable_get("@#{e}") }.compact.join(",")
23
+ @cookies.permanent[:consent] = {value: value, expires: 2.years.from_now}
24
+ end
25
+
26
+ def given?
27
+ @cookies[:consent].present?
28
+ end
29
+ end
30
+
31
+ module Consent
32
+ extend ActiveSupport::Concern
33
+
34
+ included do
35
+ helper_method :consent_settings
36
+ def consent_settings
37
+ @consent_settings ||= ConsentSettings.new(cookies)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Shimmer
4
- VERSION = "0.0.18"
4
+ VERSION = "0.0.19"
5
5
  end
data/src/consent.ts ADDED
@@ -0,0 +1,28 @@
1
+ import { getCookie, setCookie } from "./util";
2
+
3
+ export class Consent {
4
+ get permitted(): string[] {
5
+ return (getCookie("consent") ?? "").split(",");
6
+ }
7
+
8
+ set permitted(settings: string[]) {
9
+ setCookie("consent", settings.join(","));
10
+ }
11
+
12
+ get given(): boolean {
13
+ return getCookie("consent") !== undefined;
14
+ }
15
+
16
+ permitAll(): void {
17
+ this.permitted = ["essential", "targeting", "statistic"];
18
+ }
19
+
20
+ denyAll(): void {
21
+ this.permitted = ["essential"];
22
+ }
23
+
24
+ showSettings(): void {
25
+ const element = document.getElementById("personalization-settings");
26
+ if (element) element.hidden = false;
27
+ }
28
+ }
@@ -0,0 +1,51 @@
1
+ import { Controller } from "@hotwired/stimulus";
2
+
3
+ export default class extends Controller {
4
+ static targets = ["check"];
5
+ declare checkTargets: HTMLInputElement[];
6
+
7
+ connect(): void {
8
+ this.checkTargets.forEach((input) => {
9
+ input.checked =
10
+ window.ui?.consent.permitted.includes(input.name) ||
11
+ input.name === "essential";
12
+ });
13
+ }
14
+
15
+ permitAll(event: Event): void {
16
+ event.preventDefault();
17
+ window.ui?.consent.permitAll();
18
+ this.closeAll();
19
+ }
20
+
21
+ denyAll(event: Event): void {
22
+ event.preventDefault();
23
+ window.ui?.consent.denyAll();
24
+ this.closeAll();
25
+ }
26
+
27
+ save(event: Event): void {
28
+ event.preventDefault();
29
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
30
+ window.ui!.consent.permitted = this.checkTargets
31
+ .filter((e) => e.checked)
32
+ .map((e) => e.name);
33
+ this.closeAll();
34
+ }
35
+
36
+ manage(event: Event): void {
37
+ event.preventDefault();
38
+ const div = document.body.querySelector(
39
+ "#personalization-settings"
40
+ ) as HTMLDivElement;
41
+ if (!div) return;
42
+ (this.element as HTMLElement).hidden = true;
43
+ div.hidden = false;
44
+ }
45
+
46
+ closeAll(): void {
47
+ document
48
+ .querySelectorAll("[data-controller='consent']")
49
+ .forEach((e: HTMLElement) => (e.hidden = true));
50
+ }
51
+ }
data/src/index.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  import type { Application } from "@hotwired/stimulus";
2
2
  import { ModalPresenter } from "./modal";
3
3
  import { PopoverPresenter } from "./popover";
4
+ import { Consent } from "./consent";
4
5
  import RemoteNavigationController from "./controllers/remote-navigation";
6
+ import ConsentController from "./controllers/consent";
5
7
  import "./touch";
6
8
 
7
9
  export { registerServiceWorker } from "./serviceworker";
@@ -12,6 +14,7 @@ declare global {
12
14
  ui?: {
13
15
  modal: ModalPresenter;
14
16
  popover: PopoverPresenter;
17
+ consent: Consent;
15
18
  };
16
19
  }
17
20
  }
@@ -33,8 +36,10 @@ export async function start({
33
36
  window.addEventListener("turbo:load", createRemoteDestination);
34
37
  createRemoteDestination();
35
38
  application.register("remote-navigation", RemoteNavigationController);
39
+ application.register("consent", ConsentController);
36
40
  window.ui = {
37
41
  modal: new ModalPresenter(),
38
42
  popover: new PopoverPresenter(),
43
+ consent: new Consent(),
39
44
  };
40
45
  }
data/src/util.ts CHANGED
@@ -44,3 +44,22 @@ export function wait(seconds: number): Promise<void> {
44
44
  setTimeout(res, seconds * 1000);
45
45
  });
46
46
  }
47
+
48
+ export function getCookie(key: string): string | null {
49
+ if (!document.cookie) return null;
50
+ return (
51
+ document.cookie
52
+ .split(";")
53
+ .map((v) => v.split("="))
54
+ .reduce((acc, v) => {
55
+ acc[decodeURIComponent(v[0].trim())] = decodeURIComponent(v[1].trim());
56
+ return acc;
57
+ }, {})[key] ?? null
58
+ );
59
+ }
60
+
61
+ export function setCookie(key: string, value: string): void {
62
+ const date = new Date();
63
+ date.setTime(date.getTime() + 365 * 24 * 60 * 60 * 1000);
64
+ document.cookie = `${key}=${value}; expires=${date.toUTCString()}`;
65
+ }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shimmer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.18
4
+ version: 0.0.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jens Ravens
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-07-01 00:00:00.000000000 Z
11
+ date: 2022-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -154,6 +154,7 @@ files:
154
154
  - lib/shimmer/tasks/lint.rake
155
155
  - lib/shimmer/tasks/s3.rake
156
156
  - lib/shimmer/utils/config.rb
157
+ - lib/shimmer/utils/consent_settings.rb
157
158
  - lib/shimmer/utils/file_helper.rb
158
159
  - lib/shimmer/utils/file_proxy.rb
159
160
  - lib/shimmer/utils/localizable.rb
@@ -163,6 +164,8 @@ files:
163
164
  - lib/shimmer/version.rb
164
165
  - package.json
165
166
  - rollup.config.js
167
+ - src/consent.ts
168
+ - src/controllers/consent.ts
166
169
  - src/controllers/remote-navigation.ts
167
170
  - src/index.ts
168
171
  - src/locale.ts