litos-ui 0.16.2 → 0.17.0

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.
@@ -1,19 +1,23 @@
1
1
  import FormInner from "../form/form_inner";
2
- export default class CheckGroup extends FormInner {
2
+ type CheckGroupState = {
3
+ gap?: string;
4
+ };
5
+ export default class CheckGroup extends FormInner<CheckGroupState> {
3
6
  #private;
4
- checkedValues: string[];
7
+ values: Signal<string[]>;
5
8
  multiple: boolean;
6
- set value(value: string);
7
- get value(): string;
9
+ _state: CheckGroupState;
10
+ setValue(value: string): void;
8
11
  constructor();
9
12
  static get observedAttributes(): string[];
10
- attributeChange(name: string, oldValue: any, newValue: any): void;
13
+ attributeChange(name: string, _oldValue: any, newValue: any): void;
14
+ protected updateDOM(changedProps: Set<string>): void;
11
15
  connectedCallback(): void;
12
16
  afterInit(): void;
13
17
  beforeDestroy(): void;
14
18
  render(): HTMLElement;
15
- protected updatePartChild(value: string): void;
19
+ _privide: (e: CustomEvent) => void;
20
+ _updateGap: () => void;
16
21
  protected updateChecked(): void;
17
- protected updateChangedStatus(): void;
18
- protected updateChildren(): void;
19
22
  }
23
+ export {};
@@ -1,75 +1,68 @@
1
- import l from "../form/form_inner.js";
2
- import { on as u, off as r, $$ as h, iterate as d } from "ph-utils/dom";
3
- import { initAttr as c, parseAttrValue as o } from "../utils/index.js";
4
- import { isNumeric as p } from "ph-utils";
5
- const n = ":host{display:flex;align-items:center;gap:var(--l-check-gap, 0px)}";
6
- class C extends l {
7
- checkedValues;
1
+ import h from "../form/form_inner.js";
2
+ import { on as a, off as l, $$ as r } from "ph-utils/dom";
3
+ import { unitNumberStr as u } from "../utils/index.js";
4
+ import { s as c } from "../index-CrMiSe0x.js";
5
+ const o = ":host{display:flex;align-items:center;gap:var(--l-check-gap, 0px)}";
6
+ class f extends h {
7
+ values;
8
8
  multiple;
9
- set value(e) {
10
- super.setValue(e), this.rendered && this.updateChangedStatus();
11
- }
12
- get value() {
13
- return this._value;
9
+ _state;
10
+ setValue(e) {
11
+ super.setValue(e), this.rendered && this.updateChecked();
14
12
  }
15
13
  constructor() {
16
- super(!1), this.multiple = !0, this.checkedValues = [];
14
+ super(!1), this.multiple = !0, this.values = c([]), this._state = {};
17
15
  }
18
16
  static get observedAttributes() {
19
- return ["gap", "value"];
17
+ return ["disabled", "value", "name", "inner-block", "gap"];
20
18
  }
21
- attributeChange(e, t, s) {
22
- if (e === "gap") {
23
- const a = o(s, void 0);
24
- if (a) {
25
- const i = p(a) ? `${a}px` : a;
26
- this.style.setProperty("--l-check-gap", i);
27
- } else
28
- this.style.removeProperty("--l-check-gap");
29
- return;
30
- }
19
+ attributeChange(e, s, t) {
20
+ e === "gap" && (this._state.gap = u(t));
21
+ }
22
+ updateDOM(e) {
23
+ e.has("gap") && this._updateGap();
31
24
  }
32
25
  connectedCallback() {
33
- c(this), this.loadStyleText([n]), super.connectedCallback();
26
+ this.loadStyleText([o]), this.updateChecked(), super.connectedCallback(), this._updateGap();
34
27
  }
35
28
  afterInit() {
36
- u(this.root, "change", this.#e), this.updateChangedStatus();
29
+ a(this.root, "change", this.#e), a(this, "check-context-request", this._privide);
37
30
  }
38
31
  beforeDestroy() {
39
- r(this.root, "change", this.#e), this.checkedValues = [];
32
+ l(this.root, "change", this.#e), l(this, "check-context-request", this._privide), this.values([]);
40
33
  }
41
34
  render() {
42
- return h("slot");
35
+ return r("slot");
43
36
  }
37
+ _privide = (e) => {
38
+ const { context: s, callback: t } = e.detail;
39
+ s === "check-context-request" && t(this.values);
40
+ };
41
+ _updateGap = () => {
42
+ this._state.gap ? this.style.setProperty("--l-check-gap", this._state.gap) : this.style.removeProperty("--l-check-gap");
43
+ };
44
44
  #e = (e) => {
45
- e.stopPropagation(), this.updatePartChild(e.detail.value), this.setValue(e.detail.value), this.emit("change", {
46
- detail: { value: [...this.checkedValues] },
45
+ e.stopPropagation();
46
+ const s = e.detail.value, t = this.values();
47
+ let i = t.indexOf(s);
48
+ this.multiple ? (i !== -1 ? t.splice(i, 1) : t.push(s), this.setAttribute("value", t.join("&"))) : i === -1 && this.setAttribute("value", s), this.emit("change", {
49
+ detail: { value: this.multiple ? t : s },
47
50
  composed: !0
48
51
  });
49
52
  };
50
- updatePartChild(e) {
51
- }
52
53
  updateChecked() {
54
+ let e = [];
53
55
  if (this.value)
54
56
  if (this.multiple) {
55
- const e = this.value.split("&");
56
- this.checkedValues.push(...e.map((t) => decodeURIComponent(t)));
57
+ const s = this.value.split("&");
58
+ e.push(...s.map((t) => decodeURIComponent(t)));
57
59
  } else
58
- this.checkedValues = [this.value];
60
+ e = [this.value];
59
61
  else
60
- this.checkedValues = [];
61
- }
62
- updateChangedStatus() {
63
- this.updateChecked(), this.updateChildren();
64
- }
65
- updateChildren() {
66
- const e = this.children;
67
- d(e, (t) => {
68
- let s = t.value || t.getAttribute("value");
69
- s && (this.checkedValues.includes(s) ? t.setAttribute("checked", "") : t.removeAttribute("checked"));
70
- });
62
+ e = [];
63
+ this.values(e);
71
64
  }
72
65
  }
73
66
  export {
74
- C as default
67
+ f as default
75
68
  };
@@ -1,15 +1,15 @@
1
1
  import e from "./check.js";
2
- import { c as r } from "../check-D-KVLA1z.js";
3
- const c = '.l-check__inner{border-radius:50%}.l-check__inner:after{content:"";display:block;width:60%;height:60%;background-color:transparent;border-radius:50%;transition:background-color .3s ease-in-out}:host(.is-checked) .l-check__inner:after{background-color:var(--l-primary-color, #722ed1)}:host(.is-disabled) .l-check__inner{border-color:var(--l-disabled-color, #e6e6e6)}:host(.is-disabled) .l-check__inner:after{background-color:var(--l-disabled-color, #e6e6e6)}';
4
- class s extends e {
2
+ import { c as r } from "../check-CksURvTv.js";
3
+ const o = '.l-check__inner{border-radius:50%}.l-check__inner:after{content:"";display:block;width:60%;height:60%;background-color:transparent;border-radius:50%;transition:background-color .3s ease-in-out}:host(.is-checked) .l-check__inner:after{background-color:var(--l-primary-color, #722ed1)}:host(.is-disabled) .l-check__inner{border-color:var(--l-disabled-color, #e6e6e6)}:host(.is-disabled) .l-check__inner:after{background-color:var(--l-disabled-color, #e6e6e6)}';
4
+ class t extends e {
5
5
  static baseName = "radio";
6
6
  connectedCallback() {
7
- this.loadStyleText([r, c]), super.connectedCallback();
7
+ this.loadStyleText([r, o]), super.connectedCallback();
8
8
  }
9
9
  _doChangeAction() {
10
- this.setAttribute("checked", "checked"), this.emitChange();
10
+ this.setChecked(!0), this.emitChange();
11
11
  }
12
12
  }
13
13
  export {
14
- s as default
14
+ t as default
15
15
  };
@@ -2,6 +2,4 @@ import CheckGroup from ".";
2
2
  export default class RadioGroup extends CheckGroup {
3
3
  static baseName: string;
4
4
  constructor();
5
- setValue(value: string): void;
6
- protected updatePartChild(): void;
7
5
  }
@@ -1,17 +1,10 @@
1
- import t from "./index.js";
2
- import { $one as s } from "ph-utils/dom";
3
- class u extends t {
1
+ import e from "./index.js";
2
+ class s extends e {
4
3
  static baseName = "radio-group";
5
4
  constructor() {
6
5
  super(), this.multiple = !1;
7
6
  }
8
- setValue(e) {
9
- this.checkedValues = [e], super.setValue(e);
10
- }
11
- updatePartChild() {
12
- s(`[value="${this.value}"]`, this)?.removeAttribute("checked");
13
- }
14
7
  }
15
8
  export {
16
- u as default
9
+ s as default
17
10
  };
@@ -0,0 +1,4 @@
1
+ const r = ":host{--l-check-size: 14px;display:inline-flex;align-items:center;position:relative;cursor:pointer;width:auto;outline:none;transition:color .3s,border-color .3s,background-color .3s}.l-check__input{margin:0;position:absolute;z-index:-1;width:0;height:0;opacity:0}.l-check__inner{width:var(--l-check-size, 14px);height:var(--l-check-size, 14px);display:flex;justify-content:center;align-items:center;border-radius:3px;border:1px solid #dcddd9;box-sizing:border-box;transition:border-color .3s ease-in-out;position:relative;margin-right:5px;flex-shrink:0}.l-check__label{transition:color .3s;cursor:inherit;line-height:1}:host(.is-checked){color:var(--l-primary-color, #722ed1)}:host(.is-checked) .l-check__inner{border-color:var(--l-primary-color, #722ed1)}:host(.is-disabled){cursor:not-allowed}:host(.is-disabled) .l-check__label{color:var(--l-disabled-color, #e6e6e6)}:host([button]){height:var(--l-form-control-height, 32px);justify-content:center;padding:0 15px;border:1px solid #c0c4cc;border-left-width:0;margin-left:0;border-radius:inherit}:host([button]:first-child){border-left-width:1px;border-top-left-radius:3px;border-bottom-left-radius:3px}:host([button]:last-child){border-top-right-radius:3px;border-bottom-right-radius:3px}:host([button].is-checked){background-color:var(--l-primary-color, #722ed1);color:#fff;border-color:var(--l-primary-color, #722ed1);border-right-color:#fff}:host([button].is-checked:last-child){border-right-color:var(--l-primary-color, #722ed1)}";
2
+ export {
3
+ r as c
4
+ };
@@ -1,7 +1,7 @@
1
1
  import { $one as i, on as s, off as a } from "ph-utils/dom";
2
2
  import r from "../form/form_inner.js";
3
3
  import { initAttr as c, setAttrs as n } from "../utils/index.js";
4
- import { i as l } from "../index-DvcllHRh.js";
4
+ import { i as l } from "../index-Blf4-a2-.js";
5
5
  const o = ":host{--l-input-width: 60px}";
6
6
  class m extends r {
7
7
  static baseName = "color-picker";
@@ -1,13 +1,19 @@
1
1
  import BaseComponent from "../base";
2
- export default class FormInner extends BaseComponent {
2
+ import type { FormItemSignal, FormSignal } from "./types";
3
+ export default class FormInner<T = Record<string, any>> extends BaseComponent<T> {
3
4
  disabled: boolean;
4
- protected formAttrs: Record<string, any>;
5
- protected formItemAttrs: Record<string, any>;
6
5
  _value: any;
7
6
  _resetValue?: any;
8
7
  protected _firstPushValue: boolean;
9
- private _reseting;
8
+ private _isReset;
10
9
  private _name?;
10
+ formContext?: Signal<FormSignal>;
11
+ formItemContext?: Signal<FormItemSignal>;
12
+ formErrors?: Signal<Record<string, string>>;
13
+ resetCtx?: Signal<number>;
14
+ private _signalStop?;
15
+ private _errorSignalStop?;
16
+ private _resetSignalStop?;
11
17
  /**
12
18
  *
13
19
  * @param firstPushValue 是否第一次赋值 value 时, 推送数据到 Form, 默认: true
@@ -21,16 +27,17 @@ export default class FormInner extends BaseComponent {
21
27
  setValue(value: any): void;
22
28
  getValue(): any;
23
29
  static get observedAttributes(): string[];
24
- attributeChangedCallback(name: string, oldValue: string, newValue: string): void;
30
+ protected attributeChanged(name: string, oldValue: string, newValue: string): void;
25
31
  protected attributeChange(_name: string, _oldValue: string, _newValue: string): void;
26
32
  connectedCallback(): void;
27
33
  disconnectedCallback(): void;
28
- isDisabled(): any;
29
- getName(): any;
30
- private _getForm;
31
- private _formAttributeChanged;
34
+ isDisabled(): boolean;
35
+ getName(): string | undefined;
32
36
  protected disabledChange(): void;
37
+ protected innerBlockChange(_innerBlock: boolean): void;
38
+ protected validResult(_msg?: string): void;
39
+ formInject: (context: Signal<FormSignal>, errors: Signal<Record<string, string>>, reset: Signal<number>) => void;
40
+ formItemInject: (context: Signal<FormItemSignal>) => void;
33
41
  protected pushValueChange(): void;
34
- private _resetFieldValue;
35
42
  reset(): void;
36
43
  }
@@ -1,108 +1,125 @@
1
- import n from "../base.js";
2
- import { parseAttrValue as m } from "../utils/index.js";
3
- import { add as l, remove as u, emit as d } from "../utils/event.js";
4
- class b extends n {
1
+ import o from "../base.js";
2
+ import { parseAttrValue as a, stopSignal as i } from "../utils/index.js";
3
+ import { getAttr as l } from "ph-utils/dom";
4
+ import { e as n } from "../index-CrMiSe0x.js";
5
+ class _ extends o {
5
6
  disabled = !1;
6
- formAttrs = {};
7
- formItemAttrs = {};
8
- _value = "";
7
+ _value = void 0;
9
8
  _resetValue;
9
+ // 重置值(即初始化值)
10
10
  _firstPushValue = !0;
11
- _reseting = !1;
11
+ // 初始化时是否推送数据到 Form
12
+ _isReset = !1;
13
+ // 是否是重置, 重置时不触发数据校验
12
14
  _name;
15
+ formContext;
16
+ formItemContext;
17
+ formErrors;
18
+ // 表单验证错误
19
+ resetCtx;
20
+ _signalStop;
21
+ _errorSignalStop;
22
+ _resetSignalStop;
13
23
  /**
14
24
  *
15
25
  * @param firstPushValue 是否第一次赋值 value 时, 推送数据到 Form, 默认: true
16
26
  * @param delegatesFocus 是否委托焦点, 默认: true
17
27
  */
18
- constructor(t = !0, e = !0) {
19
- super(!0, { delegatesFocus: e }), this._firstPushValue = t;
28
+ constructor(e = !0, t = !0) {
29
+ super(!0, { delegatesFocus: t }), this._firstPushValue = e;
20
30
  }
21
31
  get name() {
22
32
  return this._name;
23
33
  }
24
- set name(t) {
25
- this._name = t;
34
+ set name(e) {
35
+ this._name = e;
26
36
  }
27
37
  get value() {
28
38
  return this._value;
29
39
  }
30
- set value(t) {
31
- this.setValue(t);
40
+ set value(e) {
41
+ this.setValue(e);
32
42
  }
33
- setValue(t) {
34
- this._value = t, this.pushValueChange();
43
+ setValue(e) {
44
+ this._value = e, this._resetValue == null && (this._resetValue = e), this.pushValueChange();
35
45
  }
36
46
  getValue() {
37
47
  return this._value;
38
48
  }
39
49
  static get observedAttributes() {
40
- return ["disabled", "value", "name"];
50
+ return ["disabled", "value", "name", "inner-block"];
41
51
  }
42
- attributeChangedCallback(t, e, s) {
43
- if (t === "disabled") {
44
- const i = m(s, !1, t);
45
- i !== this.disabled && (this.disabled = i, this.disabledChange());
46
- } else t === "value" || t === "name" ? this.value = s : this.attributeChange(t, e, s);
52
+ attributeChanged(e, t, s) {
53
+ switch (e) {
54
+ case "value":
55
+ case "name":
56
+ this[e] = s;
57
+ break;
58
+ case "disabled":
59
+ this.disabled = a(s, !1, e);
60
+ break;
61
+ case "inner-block":
62
+ const r = a(s, !1, e);
63
+ this.innerBlockChange(r);
64
+ break;
65
+ default:
66
+ this.attributeChange(e, t, s);
67
+ break;
68
+ }
47
69
  }
48
- attributeChange(t, e, s) {
70
+ attributeChange(e, t, s) {
49
71
  }
50
72
  connectedCallback() {
51
- const t = this._getForm();
52
- this.formAttrs = t.formAttr, this.formItemAttrs = t.formItemAttr, this.formAttrs.id && (l(this.formAttrs.id, "attributeChanged", this._formAttributeChanged), l(this.formAttrs.id, "reset", this._resetFieldValue), this._firstPushValue && this.pushValueChange()), this.formItemAttrs.id && l(this.formItemAttrs.id, "attributeChanged", this._formAttributeChanged), super.connectedCallback();
73
+ this.emitInject("form-context-request", this.formInject), this.emitInject("form-item-context-request", this.formItemInject), super.connectedCallback(), this._signalStop = n(() => {
74
+ const e = this.formItemContext ? this.formItemContext() : null, t = this.formContext ? this.formContext() : null;
75
+ if (!this.name && e && e.prop && this.setAttribute("name", e.prop), !l(this, "inner-block")) {
76
+ const r = e?.innerBlock || t?.innerBlock;
77
+ r != null && this.innerBlockChange(r);
78
+ }
79
+ }), this._value == null && (this._resetValue = "", this._firstPushValue && this.pushValueChange()), this._errorSignalStop = n(() => {
80
+ if (!this.name) return;
81
+ const t = (this.formErrors ? this.formErrors() : {})[this.name];
82
+ this.validResult(t);
83
+ }), this._resetSignalStop = n(() => {
84
+ (this.resetCtx ? this.resetCtx() : 0) > 0 && this.reset();
85
+ });
53
86
  }
54
87
  disconnectedCallback() {
55
- this.formAttrs.id && (u(this.formAttrs.id, "attributeChanged", this._formAttributeChanged), u(this.formAttrs.id, "reset", this._resetFieldValue)), this.formItemAttrs.id && u(this.formItemAttrs.id, "attributeChanged", this._formAttributeChanged), super.disconnectedCallback();
88
+ super.disconnectedCallback(), this._signalStop = i(this._signalStop), this._errorSignalStop = i(this._errorSignalStop), this._resetSignalStop = i(this._resetSignalStop);
56
89
  }
57
90
  isDisabled() {
58
- return this.disabled === !0 || this.formItemAttrs.disabled === !0 ? !0 : this.formAttrs.disabled || !1;
91
+ return this.disabled;
59
92
  }
60
93
  getName() {
61
- return this.name ? this.name : this.formItemAttrs.name || "";
62
- }
63
- _getForm() {
64
- let t = this.parentElement, e = {}, s = {};
65
- for (; t != null; ) {
66
- const i = t.tagName;
67
- if (i === "L-FORM") {
68
- const a = t.sharedAttrs;
69
- for (let r = 0; r < a.length; r++) {
70
- const h = a[r];
71
- e[h] = t[h];
72
- }
73
- break;
74
- }
75
- if (i === "BODY") break;
76
- if (i === "L-FORM-ITEM") {
77
- const a = t.sharedAttrs;
78
- for (let r = 0; r < a.length; r++) {
79
- const h = a[r];
80
- s[h] = t[h];
81
- }
82
- }
83
- t = t.parentElement;
84
- }
85
- return t = null, {
86
- formAttr: e,
87
- formItemAttr: s
88
- };
94
+ return this.name;
89
95
  }
90
- _formAttributeChanged = (t, e, s) => {
91
- s === this.formAttrs.formId ? this.formAttrs[t] = e : this.formItemAttrs[t] = e, t === "disabled" && this.disabledChange();
92
- };
93
96
  disabledChange() {
94
97
  }
95
- pushValueChange() {
96
- const t = this.getName();
97
- this.formAttrs.id && t && d(this.formAttrs.id, "valueChange", t, this._value, !this._reseting), this._reseting = !1;
98
+ innerBlockChange(e) {
99
+ }
100
+ validResult(e) {
98
101
  }
99
- _resetFieldValue = () => {
100
- this._reseting = !0, this.reset();
102
+ formInject = (e, t, s) => {
103
+ this.formContext = e, this.formErrors = t, this.resetCtx = s;
101
104
  };
105
+ formItemInject = (e) => {
106
+ this.formItemContext = e;
107
+ };
108
+ pushValueChange() {
109
+ this.name && this.emit("form-value-change", {
110
+ bubbles: !0,
111
+ composed: !0,
112
+ detail: {
113
+ name: this.name,
114
+ value: this._value,
115
+ valid: !this._isReset
116
+ }
117
+ }), this._isReset = !1;
118
+ }
102
119
  reset() {
103
- this.value = this._resetValue || "";
120
+ this._isReset = !0, this.value = this._resetValue || "", console.log("reset");
104
121
  }
105
122
  }
106
123
  export {
107
- b as default
124
+ _ as default
108
125
  };
@@ -1,39 +1,39 @@
1
- import BaseComponent from "../base";
2
1
  import type { RuleType } from "ph-utils/validator";
3
- export default class FormItem extends BaseComponent {
4
- #private;
5
- static baseName: string;
6
- disabled: boolean;
7
- sharedAttrs: string[];
8
- /** 是否必须 */
9
- required: boolean;
2
+ import ContextProvide from "../utils/context_provide";
3
+ import type { FormItemSignal } from "./types";
4
+ type FormItemState = {
10
5
  /** 标签文本 */
11
6
  label?: string;
12
- /** 内置验证规则: required - 必填, same:password - 一般用于验证确认密码和密码, phone - 验证电话号码 */
7
+ labelPosition?: "left" | "right" | "top";
8
+ error?: string;
9
+ required: boolean;
10
+ /** 内置验证规则 */
13
11
  verify?: string;
14
- /** 验证失败错误信息 */
15
- validity?: string;
16
- /** 自定义验证的正则 */
12
+ /** 正则表达式 */
17
13
  pattern?: string;
18
- name?: string;
19
- labelPosition?: "left" | "right" | "top";
20
- private formId?;
21
- innerBlock?: boolean;
14
+ /** 验证消息 */
15
+ validity?: string;
16
+ };
17
+ export default class FormItem extends ContextProvide<FormItemSignal, FormItemState> {
18
+ static baseName: string;
19
+ formErrors?: Signal<Record<string, string>>;
20
+ private _errorSignalStop?;
21
+ constructor();
22
22
  static get observedAttributes(): string[];
23
- get error(): string | undefined;
24
- set error(error: string | undefined);
25
- attributeChangedCallback(name: string, oldValue: string, newValue: string): void;
23
+ protected attributeChanged(name: string, oldValue: string, newValue: string): void;
24
+ protected updateDOM(changedProps: Set<string>): void;
26
25
  connectedCallback(): void;
27
- disconnectedCallback(): void;
26
+ beforeDestroy(): void;
28
27
  setRules(rules: {
29
28
  required?: boolean;
30
29
  rules?: RuleType[];
31
30
  message?: string;
32
31
  }): void;
33
- setError(error: string): void;
34
32
  render(): DocumentFragment;
35
- private _validateChange;
33
+ private _updateRequired;
34
+ private _parseSchema;
36
35
  private _updateError;
37
36
  private _updateLabel;
38
- private _getFormId;
37
+ private _updateRules;
39
38
  }
39
+ export {};