index17.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. import { d as h, O as m, M as S, Q as ne, P as te, h as E, u as H, y as le, aQ as oe, a8 as ue, c as R, _ as P } from "./index2.js";
  2. import { defineComponent as X, inject as re, computed as y, watchEffect as se, onBeforeUnmount as ce, onMounted as ie, ref as I, createVNode as O, watch as K, provide as de } from "vue";
  3. import { V as ve } from "./Checkbox.js";
  4. import { u as q, F as fe } from "./FormItemContext.js";
  5. import { u as z } from "./index6.js";
  6. const me = () => ({
  7. name: String,
  8. prefixCls: String,
  9. options: E([]),
  10. disabled: Boolean,
  11. id: String
  12. }), he = () => h(h({}, me()), {
  13. defaultValue: E(),
  14. value: E(),
  15. onChange: S(),
  16. "onUpdate:value": S()
  17. }), be = () => ({
  18. prefixCls: String,
  19. defaultChecked: m(),
  20. checked: m(),
  21. disabled: m(),
  22. isGroup: m(),
  23. value: te.any,
  24. name: String,
  25. id: String,
  26. indeterminate: m(),
  27. type: ne("checkbox"),
  28. autofocus: m(),
  29. onChange: S(),
  30. "onUpdate:checked": S(),
  31. onClick: S(),
  32. skipGroup: m(!1)
  33. }), pe = () => h(h({}, be()), {
  34. indeterminate: m(!1)
  35. }), J = Symbol("CheckboxGroupContext");
  36. var Q = function(e, b) {
  37. var u = {};
  38. for (var t in e) Object.prototype.hasOwnProperty.call(e, t) && b.indexOf(t) < 0 && (u[t] = e[t]);
  39. if (e != null && typeof Object.getOwnPropertySymbols == "function") for (var s = 0, t = Object.getOwnPropertySymbols(e); s < t.length; s++)
  40. b.indexOf(t[s]) < 0 && Object.prototype.propertyIsEnumerable.call(e, t[s]) && (u[t[s]] = e[t[s]]);
  41. return u;
  42. };
  43. const w = X({
  44. compatConfig: {
  45. MODE: 3
  46. },
  47. name: "ACheckbox",
  48. inheritAttrs: !1,
  49. __ANT_CHECKBOX: !0,
  50. props: pe(),
  51. // emits: ['change', 'update:checked'],
  52. setup(e, b) {
  53. let {
  54. emit: u,
  55. attrs: t,
  56. slots: s,
  57. expose: _
  58. } = b;
  59. const C = q(), M = fe.useInject(), {
  60. prefixCls: c,
  61. direction: p,
  62. disabled: j
  63. } = H("checkbox", e), $ = le(), [i, f] = z(c), l = re(J, void 0), g = Symbol("checkboxUniId"), G = y(() => (l == null ? void 0 : l.disabled.value) || j.value);
  64. se(() => {
  65. !e.skipGroup && l && l.registerValue(g, e.value);
  66. }), ce(() => {
  67. l && l.cancelValue(g);
  68. }), ie(() => {
  69. oe(!!(e.checked !== void 0 || l || e.value === void 0), "Checkbox", "`value` is not validate prop, do you mean `checked`?");
  70. });
  71. const A = (a) => {
  72. const r = a.target.checked;
  73. u("update:checked", r), u("change", a), C.onFieldChange();
  74. }, x = I();
  75. return _({
  76. focus: () => {
  77. var a;
  78. (a = x.value) === null || a === void 0 || a.focus();
  79. },
  80. blur: () => {
  81. var a;
  82. (a = x.value) === null || a === void 0 || a.blur();
  83. }
  84. }), () => {
  85. var a;
  86. const r = ue((a = s.default) === null || a === void 0 ? void 0 : a.call(s)), {
  87. indeterminate: o,
  88. skipGroup: d,
  89. id: F = C.id.value
  90. } = e, T = Q(e, ["indeterminate", "skipGroup", "id"]), {
  91. onMouseenter: D,
  92. onMouseleave: k,
  93. onInput: ge,
  94. class: W,
  95. style: Y
  96. } = t, Z = Q(t, ["onMouseenter", "onMouseleave", "onInput", "class", "style"]), v = h(h(h(h({}, T), {
  97. id: F,
  98. prefixCls: c.value
  99. }), Z), {
  100. disabled: G.value
  101. });
  102. l && !d ? (v.onChange = function() {
  103. for (var B = arguments.length, N = new Array(B), V = 0; V < B; V++)
  104. N[V] = arguments[V];
  105. u("change", ...N), l.toggleOption({
  106. label: r,
  107. value: e.value
  108. });
  109. }, v.name = l.name.value, v.checked = l.mergedValue.value.includes(e.value), v.disabled = G.value || $.value, v.indeterminate = o) : v.onChange = A;
  110. const ee = R({
  111. [`${c.value}-wrapper`]: !0,
  112. [`${c.value}-rtl`]: p.value === "rtl",
  113. [`${c.value}-wrapper-checked`]: v.checked,
  114. [`${c.value}-wrapper-disabled`]: v.disabled,
  115. [`${c.value}-wrapper-in-form-item`]: M.isFormItemInput
  116. }, W, f.value), ae = R({
  117. [`${c.value}-indeterminate`]: o
  118. }, f.value);
  119. return i(O("label", {
  120. class: ee,
  121. style: Y,
  122. onMouseenter: D,
  123. onMouseleave: k
  124. }, [O(ve, P(P({
  125. "aria-checked": o ? "mixed" : void 0
  126. }, v), {}, {
  127. class: ae,
  128. ref: x
  129. }), null), r.length ? O("span", null, [r]) : null]));
  130. };
  131. }
  132. }), U = X({
  133. compatConfig: {
  134. MODE: 3
  135. },
  136. name: "ACheckboxGroup",
  137. inheritAttrs: !1,
  138. props: he(),
  139. // emits: ['change', 'update:value'],
  140. setup(e, b) {
  141. let {
  142. slots: u,
  143. attrs: t,
  144. emit: s,
  145. expose: _
  146. } = b;
  147. const C = q(), {
  148. prefixCls: M,
  149. direction: c
  150. } = H("checkbox", e), p = y(() => `${M.value}-group`), [j, $] = z(p), i = I((e.value === void 0 ? e.defaultValue : e.value) || []);
  151. K(() => e.value, () => {
  152. i.value = e.value || [];
  153. });
  154. const f = y(() => e.options.map((n) => typeof n == "string" || typeof n == "number" ? {
  155. label: n,
  156. value: n
  157. } : n)), l = I(Symbol()), g = I(/* @__PURE__ */ new Map()), G = (n) => {
  158. g.value.delete(n), l.value = Symbol();
  159. }, A = (n, a) => {
  160. g.value.set(n, a), l.value = Symbol();
  161. }, x = I(/* @__PURE__ */ new Map());
  162. return K(l, () => {
  163. const n = /* @__PURE__ */ new Map();
  164. for (const a of g.value.values())
  165. n.set(a, !0);
  166. x.value = n;
  167. }), de(J, {
  168. cancelValue: G,
  169. registerValue: A,
  170. toggleOption: (n) => {
  171. const a = i.value.indexOf(n.value), r = [...i.value];
  172. a === -1 ? r.push(n.value) : r.splice(a, 1), e.value === void 0 && (i.value = r);
  173. const o = r.filter((d) => x.value.has(d)).sort((d, F) => {
  174. const T = f.value.findIndex((k) => k.value === d), D = f.value.findIndex((k) => k.value === F);
  175. return T - D;
  176. });
  177. s("update:value", o), s("change", o), C.onFieldChange();
  178. },
  179. mergedValue: i,
  180. name: y(() => e.name),
  181. disabled: y(() => e.disabled)
  182. }), _({
  183. mergedValue: i
  184. }), () => {
  185. var n;
  186. const {
  187. id: a = C.id.value
  188. } = e;
  189. let r = null;
  190. return f.value && f.value.length > 0 && (r = f.value.map((o) => {
  191. var d;
  192. return O(w, {
  193. prefixCls: M.value,
  194. key: o.value.toString(),
  195. disabled: "disabled" in o ? o.disabled : e.disabled,
  196. indeterminate: o.indeterminate,
  197. value: o.value,
  198. checked: i.value.indexOf(o.value) !== -1,
  199. onChange: o.onChange,
  200. class: `${p.value}-item`
  201. }, {
  202. default: () => [u.label !== void 0 ? (d = u.label) === null || d === void 0 ? void 0 : d.call(u, o) : o.label]
  203. });
  204. })), j(O("div", P(P({}, t), {}, {
  205. class: [p.value, {
  206. [`${p.value}-rtl`]: c.value === "rtl"
  207. }, t.class, $.value],
  208. id: a
  209. }), [r || ((n = u.default) === null || n === void 0 ? void 0 : n.call(u))]));
  210. };
  211. }
  212. });
  213. w.Group = U;
  214. w.install = function(e) {
  215. return e.component(w.name, w), e.component(U.name, U), e;
  216. };
  217. export {
  218. w as C
  219. };