y-design-ssr 0.2.0 → 0.2.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 (119) hide show
  1. package/libs/button/index.css +579 -1
  2. package/libs/button/index.mjs +111 -66
  3. package/libs/button/index.umd.js +203 -2
  4. package/libs/cell/index.css +1077 -1
  5. package/libs/cell/index.mjs +167 -104
  6. package/libs/cell/index.umd.js +300 -2
  7. package/libs/checkbox/index.css +1053 -1
  8. package/libs/checkbox/index.mjs +242 -127
  9. package/libs/checkbox/index.umd.js +369 -2
  10. package/libs/checkboxGroup/index.css +422 -1
  11. package/libs/checkboxGroup/index.mjs +173 -87
  12. package/libs/checkboxGroup/index.umd.js +265 -2
  13. package/libs/col/index.css +615 -1
  14. package/libs/col/index.mjs +246 -81
  15. package/libs/col/index.umd.js +305 -2
  16. package/libs/countdown/index.css +417 -1
  17. package/libs/countdown/index.mjs +179 -71
  18. package/libs/countdown/index.umd.js +231 -2
  19. package/libs/dialog/index.css +1405 -1
  20. package/libs/dialog/index.mjs +646 -476
  21. package/libs/dialog/index.umd.js +1128 -2
  22. package/libs/empty/index.css +457 -1
  23. package/libs/empty/index.mjs +91 -44
  24. package/libs/empty/index.umd.js +139 -2
  25. package/libs/form/index.css +477 -1
  26. package/libs/form/index.mjs +226 -126
  27. package/libs/form/index.umd.js +319 -2
  28. package/libs/formItem/index.css +477 -1
  29. package/libs/formItem/index.mjs +276 -126
  30. package/libs/formItem/index.umd.js +372 -2
  31. package/libs/icon/index.css +982 -1
  32. package/libs/icon/index.mjs +107 -58
  33. package/libs/icon/index.umd.js +186 -2
  34. package/libs/index.css +2902 -1
  35. package/libs/index.mjs +3785 -2344
  36. package/libs/index.umd.js +5509 -2
  37. package/libs/input/index.css +483 -1
  38. package/libs/input/index.mjs +183 -92
  39. package/libs/input/index.umd.js +274 -2
  40. package/libs/layout/index.css +684 -1
  41. package/libs/layout/index.mjs +230 -130
  42. package/libs/layout/index.umd.js +318 -2
  43. package/libs/list/index.css +440 -1
  44. package/libs/list/index.mjs +388 -207
  45. package/libs/list/index.umd.js +571 -2
  46. package/libs/loading/index.css +548 -1
  47. package/libs/loading/index.mjs +196 -118
  48. package/libs/loading/index.umd.js +321 -2
  49. package/libs/mask/index.css +426 -1
  50. package/libs/mask/index.mjs +131 -70
  51. package/libs/mask/index.umd.js +201 -2
  52. package/libs/popup/index.css +465 -1
  53. package/libs/popup/index.mjs +210 -134
  54. package/libs/popup/index.umd.js +358 -2
  55. package/libs/progress/index.css +488 -1
  56. package/libs/progress/index.mjs +200 -128
  57. package/libs/progress/index.umd.js +322 -2
  58. package/libs/pullrefresh/index.css +441 -1
  59. package/libs/pullrefresh/index.mjs +241 -111
  60. package/libs/pullrefresh/index.umd.js +302 -2
  61. package/libs/row/index.css +485 -1
  62. package/libs/row/index.mjs +181 -89
  63. package/libs/row/index.umd.js +237 -2
  64. package/libs/slider/index.css +558 -1
  65. package/libs/slider/index.mjs +356 -160
  66. package/libs/slider/index.umd.js +453 -2
  67. package/libs/stepper/index.css +489 -1
  68. package/libs/stepper/index.mjs +181 -101
  69. package/libs/stepper/index.umd.js +269 -2
  70. package/libs/swipe/index.css +506 -1
  71. package/libs/swipe/index.mjs +542 -259
  72. package/libs/swipe/index.umd.js +703 -2
  73. package/libs/swipeItem/index.css +424 -1
  74. package/libs/swipeItem/index.mjs +111 -52
  75. package/libs/swipeItem/index.umd.js +154 -2
  76. package/libs/switch/index.css +472 -1
  77. package/libs/switch/index.mjs +121 -62
  78. package/libs/switch/index.umd.js +200 -2
  79. package/libs/tab/index.mjs +131 -68
  80. package/libs/tab/index.umd.js +190 -1
  81. package/libs/tabs/index.css +514 -1
  82. package/libs/tabs/index.mjs +751 -410
  83. package/libs/tabs/index.umd.js +1020 -2
  84. package/libs/toast/index.css +1050 -1
  85. package/libs/toast/index.mjs +183 -114
  86. package/libs/toast/index.umd.js +306 -2
  87. package/libs/tooltip/index.css +514 -1
  88. package/libs/tooltip/index.mjs +293 -155
  89. package/libs/tooltip/index.umd.js +416 -2
  90. package/package.json +5 -4
  91. package/libs/button/package.json +0 -5
  92. package/libs/cell/package.json +0 -5
  93. package/libs/checkbox/package.json +0 -5
  94. package/libs/checkboxGroup/package.json +0 -5
  95. package/libs/col/package.json +0 -5
  96. package/libs/countdown/package.json +0 -5
  97. package/libs/dialog/package.json +0 -5
  98. package/libs/empty/package.json +0 -5
  99. package/libs/form/package.json +0 -5
  100. package/libs/formItem/package.json +0 -5
  101. package/libs/icon/package.json +0 -5
  102. package/libs/input/package.json +0 -5
  103. package/libs/layout/package.json +0 -5
  104. package/libs/list/package.json +0 -5
  105. package/libs/loading/package.json +0 -5
  106. package/libs/mask/package.json +0 -5
  107. package/libs/popup/package.json +0 -5
  108. package/libs/progress/package.json +0 -5
  109. package/libs/pullrefresh/package.json +0 -5
  110. package/libs/row/package.json +0 -5
  111. package/libs/slider/package.json +0 -5
  112. package/libs/stepper/package.json +0 -5
  113. package/libs/swipe/package.json +0 -5
  114. package/libs/swipeItem/package.json +0 -5
  115. package/libs/switch/package.json +0 -5
  116. package/libs/tab/package.json +0 -5
  117. package/libs/tabs/package.json +0 -5
  118. package/libs/toast/package.json +0 -5
  119. package/libs/tooltip/package.json +0 -5
@@ -1,11 +1,48 @@
1
- import { ref as y, reactive as w, inject as z, getCurrentInstance as R, onUnmounted as j, computed as p, provide as W, defineComponent as D, createVNode as h } from "vue";
2
- const O = (t) => (e) => Object.prototype.toString.call(e) === `[object ${t}]`, L = O("Function"), G = O("String"), U = O("Object"), x = (t, e) => e ? typeof e == "string" ? ` ${t}--${e}` : Array.isArray(e) ? e.reduce((i, r) => i + x(t, r), "") : Object.keys(e).reduce(
3
- (i, r) => i + (e[r] ? x(t, r) : ""),
4
- ""
5
- ) : "", k = (t) => (e, i) => {
6
- let r = e, d = i;
7
- return r && typeof r != "string" && (d = r, r = ""), r = r ? `${t}__${r}` : t, `${r}${x(r, d)}`;
8
- }, H = () => (t, e) => e ? `${x(`y-${t}`, e)}` : `y-${t}`, J = {
1
+ import { ref, reactive, inject, getCurrentInstance, onUnmounted, computed, provide, defineComponent, createVNode } from "vue";
2
+ const tagTester = (name2) => {
3
+ return (obj) => {
4
+ return Object.prototype.toString.call(obj) === `[object ${name2}]`;
5
+ };
6
+ };
7
+ const isFunction = tagTester("Function");
8
+ const isString = tagTester("String");
9
+ const isObject = tagTester("Object");
10
+ const getMods = (el, mods) => {
11
+ if (!mods) {
12
+ return "";
13
+ }
14
+ if (typeof mods === "string") {
15
+ return ` ${el}--${mods}`;
16
+ }
17
+ if (Array.isArray(mods)) {
18
+ return mods.reduce((acc, cur) => acc + getMods(el, cur), "");
19
+ }
20
+ return Object.keys(mods).reduce(
21
+ (acc, cur) => acc + (mods[cur] ? getMods(el, cur) : ""),
22
+ ""
23
+ );
24
+ };
25
+ const createBEM = (block) => {
26
+ return (el, mods) => {
27
+ let _el = el;
28
+ let _mods = mods;
29
+ if (_el && typeof _el !== "string") {
30
+ _mods = _el;
31
+ _el = "";
32
+ }
33
+ _el = _el ? `${block}__${_el}` : block;
34
+ return `${_el}${getMods(_el, _mods)}`;
35
+ };
36
+ };
37
+ const createGlobalBem = () => {
38
+ return (el, mods) => {
39
+ if (!mods) {
40
+ return `y-${el}`;
41
+ }
42
+ return `${getMods(`y-${el}`, mods)}`;
43
+ };
44
+ };
45
+ const defaultLang = {
9
46
  "pull-refresh": {
10
47
  pulling: "下拉刷新...",
11
48
  loosing: "释放刷新...",
@@ -16,56 +53,77 @@ const O = (t) => (e) => Object.prototype.toString.call(e) === `[object ${t}]`, L
16
53
  "form-item": {
17
54
  validateMessage: "请输入正确内容"
18
55
  }
19
- }, I = y("zh-CN"), F = w({
20
- "zh-CN": J
21
- }), K = {
56
+ };
57
+ const lang = ref("zh-CN");
58
+ const langs = reactive({
59
+ "zh-CN": defaultLang
60
+ });
61
+ const locale$1 = {
22
62
  text() {
23
- return F[I.value];
63
+ return langs[lang.value];
24
64
  },
25
- use(t, e) {
26
- I.value = t, this.add({ [t]: e });
65
+ use(newLang, newConfigs) {
66
+ lang.value = newLang;
67
+ this.add({ [newLang]: newConfigs });
27
68
  },
28
- add(t = {}) {
29
- Object.assign(F, t);
69
+ add(newConfigs = {}) {
70
+ Object.assign(langs, newConfigs);
30
71
  }
31
- }, _ = (t) => {
32
- const e = `y-${t}`;
33
- return [e, k(e), H()];
34
- }, Q = (t) => K.text()[t], X = (t) => {
35
- const e = z(t, null), i = R();
36
- if (e && i) {
37
- const { childrens: r, addChild: d, removeChild: o } = e;
38
- return d(i), j(() => o(i)), {
39
- index: p(() => r.indexOf(i)),
40
- parent: e
72
+ };
73
+ const createNamespace = (name2) => {
74
+ const prefixedName = `y-${name2}`;
75
+ return [prefixedName, createBEM(prefixedName), createGlobalBem()];
76
+ };
77
+ const createLocale = (name2) => {
78
+ return locale$1.text()[name2];
79
+ };
80
+ const useRelation = (key) => {
81
+ const parent = inject(key, null);
82
+ const currentInstance = getCurrentInstance();
83
+ if (parent && currentInstance) {
84
+ const { childrens, addChild, removeChild } = parent;
85
+ addChild(currentInstance);
86
+ onUnmounted(() => removeChild(currentInstance));
87
+ const index = computed(() => childrens.indexOf(currentInstance));
88
+ return {
89
+ index,
90
+ parent
41
91
  };
42
92
  }
43
93
  return {
44
94
  parent: null,
45
- index: y(-1)
95
+ index: ref(-1)
96
+ };
97
+ };
98
+ const FORM_ITEM_PROVIDE = "y-form-item";
99
+ const setFormItem = () => {
100
+ const instance = getCurrentInstance();
101
+ const filed = ref();
102
+ const initProvide = (value) => {
103
+ const setField = (obj) => {
104
+ if (obj == null ? void 0 : obj.proxy) {
105
+ filed.value = obj;
106
+ }
107
+ };
108
+ provide(FORM_ITEM_PROVIDE, {
109
+ setField,
110
+ instance,
111
+ ...value
112
+ });
46
113
  };
47
- }, Y = "y-form-item", Z = () => {
48
- const t = R(), e = y();
49
114
  return {
50
- filed: e,
51
- initProvide: (r) => {
52
- W(Y, {
53
- setField: (o) => {
54
- o != null && o.proxy && (e.value = o);
55
- },
56
- instance: t,
57
- ...r
58
- });
59
- }
115
+ filed,
116
+ initProvide
60
117
  };
61
- }, ee = {
118
+ };
119
+ const commonProps = {
62
120
  size: {
63
121
  type: String,
64
122
  default: null
65
123
  },
66
124
  border: {
67
125
  type: Boolean,
68
- default: !0
126
+ default: true
69
127
  },
70
128
  labelWidth: {
71
129
  type: [Number, String],
@@ -74,7 +132,7 @@ const O = (t) => (e) => Object.prototype.toString.call(e) === `[object ${t}]`, L
74
132
  colon: {
75
133
  // 是否有 ":"
76
134
  type: Boolean,
77
- default: !1
135
+ default: false
78
136
  },
79
137
  labelAlign: {
80
138
  type: String,
@@ -82,11 +140,11 @@ const O = (t) => (e) => Object.prototype.toString.call(e) === `[object ${t}]`, L
82
140
  },
83
141
  showError: {
84
142
  type: Boolean,
85
- default: !0
143
+ default: true
86
144
  },
87
145
  showErrorMessage: {
88
146
  type: Boolean,
89
- default: !0
147
+ default: true
90
148
  },
91
149
  errorMessageAlign: {
92
150
  type: String,
@@ -96,10 +154,16 @@ const O = (t) => (e) => Object.prototype.toString.call(e) === `[object ${t}]`, L
96
154
  type: [Object, Array],
97
155
  default: null
98
156
  }
99
- }, [te, oe] = _("form"), re = te, C = "form-item", [ne, b, le] = _(C), ae = Q(C), $ = /* @__PURE__ */ D({
100
- name: ne,
157
+ };
158
+ const [name$1, bem$1] = createNamespace("form");
159
+ const FORM_PROVIDE = name$1;
160
+ const COMPONENT_NAME = "form-item";
161
+ const [name, bem, gbem] = createNamespace(COMPONENT_NAME);
162
+ const locale = createLocale(COMPONENT_NAME);
163
+ const FormItem = /* @__PURE__ */ defineComponent({
164
+ name,
101
165
  props: {
102
- ...ee,
166
+ ...commonProps,
103
167
  label: {
104
168
  type: [Number, String],
105
169
  default: ""
@@ -114,103 +178,189 @@ const O = (t) => (e) => Object.prototype.toString.call(e) === `[object ${t}]`, L
114
178
  default: ""
115
179
  }
116
180
  },
117
- setup(t, {
118
- slots: e,
119
- expose: i
181
+ setup(props, {
182
+ slots,
183
+ expose
120
184
  }) {
121
185
  const {
122
- parent: r
123
- } = X(re), {
124
- initProvide: d,
125
- filed: o
126
- } = Z(), c = y(!1), v = y(ae.validateMessage), f = (n) => {
127
- if (t[n] && t[n] !== null)
128
- return t[n];
129
- const l = r && r.props;
130
- return l && l[n] || null;
131
- }, g = p(() => {
132
- const n = r && r.props.rules, l = t.rules || (n == null ? void 0 : n[t.prop]);
133
- return U(l) ? [l] : l;
134
- }), N = p(() => g.value && g.value.some((n) => n.required)), M = p(() => o.value ? o.value.proxy.modelValue : null), A = p(() => f("showError") && c.value), q = (n, l) => !(l.required && (o.value && o.value.exposed && typeof o.value.exposed.isRequired < "u" && !o.value.exposed.isRequired || !(Array.isArray(n) ? n.length : n)) || l.pattern && G(n) && !l.pattern.test(n)), P = (n, l) => {
186
+ parent
187
+ } = useRelation(FORM_PROVIDE);
188
+ const {
189
+ initProvide: initFormItemProvide,
190
+ filed
191
+ } = setFormItem();
192
+ const validateFailed = ref(false);
193
+ const validateMessage = ref(locale.validateMessage);
194
+ const getProp = (propName) => {
195
+ if (props[propName] && props[propName] !== null)
196
+ return props[propName];
197
+ const parentProps = parent && parent.props;
198
+ return parentProps && parentProps[propName] || null;
199
+ };
200
+ const rules = computed(() => {
201
+ const parentRules = parent && parent.props.rules;
202
+ const curRules = props.rules || (parentRules == null ? void 0 : parentRules[props.prop]);
203
+ return isObject(curRules) ? [curRules] : curRules;
204
+ });
205
+ const required = computed(() => rules.value && rules.value.some((item) => item.required));
206
+ const formValue = computed(() => {
207
+ if (filed.value) {
208
+ const filedInstance = filed.value.proxy;
209
+ return filedInstance.modelValue;
210
+ }
211
+ return null;
212
+ });
213
+ const errorStatus = computed(() => {
214
+ return getProp("showError") && validateFailed.value;
215
+ });
216
+ const runSyncRule = (value, rule) => {
217
+ if (rule.required) {
218
+ if (filed.value && filed.value.exposed && typeof filed.value.exposed.isRequired !== "undefined" && !filed.value.exposed.isRequired) {
219
+ return false;
220
+ }
221
+ if (!(Array.isArray(value) ? value.length : value)) {
222
+ return false;
223
+ }
224
+ }
225
+ if (rule.pattern && isString(value) && !rule.pattern.test(value)) {
226
+ return false;
227
+ }
228
+ return true;
229
+ };
230
+ const getRuleMessage = (value, rule) => {
135
231
  const {
136
- message: a
137
- } = l;
138
- return L(a) ? a(n, l) : a;
139
- }, B = (n) => n.reduce((l, a) => l.then(() => {
140
- if (c.value)
232
+ message
233
+ } = rule;
234
+ if (isFunction(message)) {
235
+ return message(value, rule);
236
+ }
237
+ return message;
238
+ };
239
+ const runRules = (ruleList) => {
240
+ return ruleList.reduce((promise, rule) => promise.then(() => {
241
+ if (validateFailed.value)
242
+ return null;
243
+ const value = rule.formatter ? rule.formatter(formValue.value, rule) : formValue.value;
244
+ if (!runSyncRule(value, rule)) {
245
+ validateFailed.value = true;
246
+ validateMessage.value = getRuleMessage(value, rule);
247
+ return null;
248
+ }
249
+ if (rule.validator) {
250
+ const cb = rule.validator(value, rule);
251
+ if (typeof cb === "boolean") {
252
+ if (!cb) {
253
+ validateFailed.value = true;
254
+ validateMessage.value = getRuleMessage(value, rule);
255
+ }
256
+ return Promise.resolve(cb);
257
+ }
258
+ return cb.then((result) => {
259
+ if (!result) {
260
+ validateFailed.value = true;
261
+ validateMessage.value = getRuleMessage(value, rule);
262
+ }
263
+ return result;
264
+ });
265
+ }
141
266
  return null;
142
- const u = a.formatter ? a.formatter(M.value, a) : M.value;
143
- if (!q(u, a))
144
- return c.value = !0, v.value = P(u, a), null;
145
- if (a.validator) {
146
- const s = a.validator(u, a);
147
- return typeof s == "boolean" ? (s || (c.value = !0, v.value = P(u, a)), Promise.resolve(s)) : s.then((m) => (m || (c.value = !0, v.value = P(u, a)), m));
267
+ }), Promise.resolve());
268
+ };
269
+ const validate = async (ruleList) => {
270
+ const ruleArr = ruleList || rules.value;
271
+ if (!ruleArr) {
272
+ return Promise.resolve();
273
+ }
274
+ await runRules(ruleArr);
275
+ if (validateFailed.value) {
276
+ return {
277
+ name: props.prop,
278
+ message: validateMessage.value
279
+ };
148
280
  }
149
281
  return null;
150
- }), Promise.resolve()), S = async (n) => {
151
- const l = n || g.value;
152
- return l ? (await B(l), c.value ? {
153
- name: t.prop,
154
- message: v.value
155
- } : null) : Promise.resolve();
156
- }, T = (n) => {
157
- var l;
158
- if (r && g.value) {
159
- const a = ((l = r.props) == null ? void 0 : l.validateTrigger) === n, u = g.value.filter((s) => s.trigger ? s.trigger === n : a);
160
- return S(u);
282
+ };
283
+ const validateWithTrigger = (trigger) => {
284
+ var _a;
285
+ if (parent && rules.value) {
286
+ const defaultTrigger = ((_a = parent.props) == null ? void 0 : _a.validateTrigger) === trigger;
287
+ const ruleList = rules.value.filter((rule) => {
288
+ if (rule.trigger) {
289
+ return rule.trigger === trigger;
290
+ }
291
+ return defaultTrigger;
292
+ });
293
+ return validate(ruleList);
161
294
  }
162
295
  return Promise.resolve(null);
163
- }, E = () => {
164
- c.value && (c.value = !1, v.value = "");
165
296
  };
166
- d({
167
- getProp: f,
168
- validateWithTrigger: T,
169
- resetValidation: E,
170
- change: r == null ? void 0 : r.change
171
- }), i({
172
- resetValidation: E,
173
- formValue: M,
174
- validate: S
175
- });
176
- const V = () => A.value ? e.error ? e.error() : f("showErrorMessage") ? h("p", {
177
- class: b("error"),
178
- style: {
179
- textAlign: "left"
297
+ const resetValidation = () => {
298
+ if (validateFailed.value) {
299
+ validateFailed.value = false;
300
+ validateMessage.value = "";
180
301
  }
181
- }, [v.value]) : null : null;
302
+ };
303
+ initFormItemProvide({
304
+ getProp,
305
+ validateWithTrigger,
306
+ resetValidation,
307
+ change: parent == null ? void 0 : parent.change
308
+ });
309
+ expose({
310
+ resetValidation,
311
+ formValue,
312
+ validate
313
+ });
314
+ const _renderError = () => {
315
+ if (!errorStatus.value)
316
+ return null;
317
+ if (slots.error)
318
+ return slots.error();
319
+ return getProp("showErrorMessage") ? createVNode("p", {
320
+ "class": bem("error"),
321
+ "style": {
322
+ textAlign: "left"
323
+ }
324
+ }, [validateMessage.value]) : null;
325
+ };
182
326
  return () => {
183
- var u, s, m;
327
+ var _a, _b, _c;
184
328
  const {
185
- label: n,
186
- border: l,
187
- colon: a
188
- } = t;
189
- return h("div", {
190
- class: [b({
191
- "is-error": A.value,
192
- [f("size")]: f("size"),
193
- hairline: l
194
- }), le("el", {
195
- "hairline-bottom": l
329
+ label,
330
+ border,
331
+ colon
332
+ } = props;
333
+ return createVNode("div", {
334
+ "class": [bem({
335
+ "is-error": errorStatus.value,
336
+ [getProp("size")]: getProp("size"),
337
+ hairline: border
338
+ }), gbem("el", {
339
+ "hairline-bottom": border
196
340
  })]
197
- }, [h("label", {
198
- class: b("label", {
199
- "is-required": N.value
341
+ }, [createVNode("label", {
342
+ "class": bem("label", {
343
+ "is-required": required.value
200
344
  }),
201
- style: {
202
- width: f("labelWidth"),
203
- textAlign: f("labelAlign") || "left"
345
+ "style": {
346
+ width: getProp("labelWidth"),
347
+ textAlign: getProp("labelAlign") || "left"
204
348
  }
205
- }, [(u = e.labelIcon) == null ? void 0 : u.call(e), n, a ? " :" : ""]), h("div", {
206
- class: b("content")
207
- }, [(s = e.default) == null ? void 0 : s.call(e), V()]), (m = e.extra) == null ? void 0 : m.call(e)]);
349
+ }, [(_a = slots.labelIcon) == null ? void 0 : _a.call(slots), label, colon ? " :" : ""]), createVNode("div", {
350
+ "class": bem("content")
351
+ }, [(_b = slots.default) == null ? void 0 : _b.call(slots), _renderError()]), (_c = slots.extra) == null ? void 0 : _c.call(slots)]);
208
352
  };
209
353
  }
210
354
  });
211
- $.install = (t) => {
212
- t.component($.name, $);
355
+ const reset = "";
356
+ const libs = "";
357
+ const font = "";
358
+ const animation = "";
359
+ const theme = "";
360
+ const style = "";
361
+ FormItem.install = (Vue) => {
362
+ Vue.component(FormItem.name, FormItem);
213
363
  };
214
364
  export {
215
- $ as default
365
+ FormItem as default
216
366
  };