Welcome to mirror list, hosted at ThFree Co, Russian Federation.

module.esm.js « dist « ui « packages « alpinejs - github.com/gohugoio/hugo-mod-jslibs-dist.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f5541356fd1f5aa0e9df4e60582363e3e7eee1f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// packages/ui/src/dialog.js
function dialog_default(Alpine) {
  Alpine.directive("dialog", (el, directive) => {
    if (directive.value === "overlay")
      handleOverlay(el, Alpine);
    else if (directive.value === "panel")
      handlePanel(el, Alpine);
    else if (directive.value === "title")
      handleTitle(el, Alpine);
    else if (directive.value === "description")
      handleDescription(el, Alpine);
    else
      handleRoot(el, Alpine);
  });
  Alpine.magic("dialog", (el) => {
    let $data = Alpine.$data(el);
    return {
      get open() {
        return $data.__isOpen;
      },
      close() {
        $data.__close();
      }
    };
  });
}
function handleRoot(el, Alpine) {
  Alpine.bind(el, {
    "x-data"() {
      return {
        init() {
          Alpine.bound(el, "open") !== void 0 && Alpine.effect(() => {
            this.__isOpenState = Alpine.bound(el, "open");
          });
          if (Alpine.bound(el, "initial-focus") !== void 0)
            this.$watch("__isOpenState", () => {
              if (!this.__isOpenState)
                return;
              setTimeout(() => {
                Alpine.bound(el, "initial-focus").focus();
              }, 0);
            });
        },
        __isOpenState: false,
        __close() {
          if (Alpine.bound(el, "open"))
            this.$dispatch("close");
          else
            this.__isOpenState = false;
        },
        get __isOpen() {
          return Alpine.bound(el, "static", this.__isOpenState);
        }
      };
    },
    "x-modelable": "__isOpenState",
    "x-id"() {
      return ["alpine-dialog-title", "alpine-dialog-description"];
    },
    "x-show"() {
      return this.__isOpen;
    },
    "x-trap.inert.noscroll"() {
      return this.__isOpen;
    },
    "@keydown.escape"() {
      this.__close();
    },
    ":aria-labelledby"() {
      return this.$id("alpine-dialog-title");
    },
    ":aria-describedby"() {
      return this.$id("alpine-dialog-description");
    },
    role: "dialog",
    "aria-modal": "true"
  });
}
function handleOverlay(el, Alpine) {
  Alpine.bind(el, {
    "x-init"() {
      if (this.$data.__isOpen === void 0)
        console.warn('"x-dialog:overlay" is missing a parent element with "x-dialog".');
    },
    "x-show"() {
      return this.__isOpen;
    },
    "@click.prevent.stop"() {
      this.$data.__close();
    }
  });
}
function handlePanel(el, Alpine) {
  Alpine.bind(el, {
    "@click.outside"() {
      this.$data.__close();
    },
    "x-show"() {
      return this.$data.__isOpen;
    }
  });
}
function handleTitle(el, Alpine) {
  Alpine.bind(el, {
    "x-init"() {
      if (this.$data.__isOpen === void 0)
        console.warn('"x-dialog:title" is missing a parent element with "x-dialog".');
    },
    ":id"() {
      return this.$id("alpine-dialog-title");
    }
  });
}
function handleDescription(el, Alpine) {
  Alpine.bind(el, {
    ":id"() {
      return this.$id("alpine-dialog-description");
    }
  });
}

// packages/ui/src/index.js
function src_default(Alpine) {
  dialog_default(Alpine);
}

// packages/ui/builds/module.js
var module_default = src_default;
export {
  module_default as default
};