@fluid-topics/ft-wc-utils 2.0.36 → 2.0.38
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.
- package/build/FtLitElementWithConditionalVisibility.d.ts +10 -0
- package/build/FtLitElementWithConditionalVisibility.js +48 -0
- package/build/ft-input/FtInput.js +5 -9
- package/build/ft-input/ValidationRules.d.ts +2 -0
- package/build/ft-input/ValidationRules.js +21 -4
- package/build/globals.min.js +13 -13
- package/build/index.d.ts +1 -0
- package/build/index.js +3 -0
- package/package.json +3 -3
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { FtLitElement } from "./FtLitElement";
|
|
2
|
+
import { Constructor } from "./generic-types";
|
|
3
|
+
export interface FtLitElementWithConditionalVisibilityInterface {
|
|
4
|
+
forceVisible: boolean;
|
|
5
|
+
isVisible: boolean;
|
|
6
|
+
isElementWithConditionalVisibility: boolean;
|
|
7
|
+
}
|
|
8
|
+
type FtLitElementWithConditionalVisibilityType<T extends Constructor<FtLitElement>> = T & Constructor<FtLitElementWithConditionalVisibilityInterface>;
|
|
9
|
+
export declare function withConditionalVisibility<T extends Constructor<FtLitElement>>(Class: T): FtLitElementWithConditionalVisibilityType<T>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { property, state, } from "lit/decorators.js";
|
|
8
|
+
export function withConditionalVisibility(Class) {
|
|
9
|
+
class FtLitElementWithConditionalVisibilityClass extends Class {
|
|
10
|
+
constructor() {
|
|
11
|
+
super(...arguments);
|
|
12
|
+
this.forceVisible = false;
|
|
13
|
+
this.isVisible = true;
|
|
14
|
+
this.isElementWithConditionalVisibility = true;
|
|
15
|
+
}
|
|
16
|
+
calculateStyles(condition, styleString) {
|
|
17
|
+
if (condition) {
|
|
18
|
+
const style = document.createElement("style");
|
|
19
|
+
style.classList.add("conditional-visibility-style");
|
|
20
|
+
style.innerHTML = styleString;
|
|
21
|
+
this.shadowRoot.append(style);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
hideIfNecessary() {
|
|
25
|
+
const isHidden = !(this.forceVisible || this.isVisible);
|
|
26
|
+
this.calculateStyles(isHidden, ":host { display: none !important; }");
|
|
27
|
+
}
|
|
28
|
+
highlightIfForceVisible() {
|
|
29
|
+
this.calculateStyles(this.forceVisible, ":host { box-shadow: 0px 0px 0px 8px rgba(227,119,59,0.4) inset; }");
|
|
30
|
+
}
|
|
31
|
+
willUpdate(props) {
|
|
32
|
+
super.willUpdate(props);
|
|
33
|
+
this.updateComplete.then(() => {
|
|
34
|
+
this.shadowRoot.querySelectorAll(".conditional-visibility-style")
|
|
35
|
+
.forEach((element) => element.remove());
|
|
36
|
+
this.hideIfNecessary();
|
|
37
|
+
this.highlightIfForceVisible();
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
__decorate([
|
|
42
|
+
property({ type: Boolean, attribute: false })
|
|
43
|
+
], FtLitElementWithConditionalVisibilityClass.prototype, "forceVisible", void 0);
|
|
44
|
+
__decorate([
|
|
45
|
+
state()
|
|
46
|
+
], FtLitElementWithConditionalVisibilityClass.prototype, "isVisible", void 0);
|
|
47
|
+
return FtLitElementWithConditionalVisibilityClass;
|
|
48
|
+
}
|
|
@@ -4,10 +4,11 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
import {
|
|
7
|
+
import { processValidationRules, } from "./ValidationRules";
|
|
8
|
+
import { property, state, } from "lit/decorators.js";
|
|
8
9
|
import { repeat } from "lit/directives/repeat.js";
|
|
9
10
|
import { when } from "lit/directives/when.js";
|
|
10
|
-
import { html } from "lit";
|
|
11
|
+
import { html, } from "lit";
|
|
11
12
|
import { applyMixinOnce } from "../helpers";
|
|
12
13
|
export var ValidateOn;
|
|
13
14
|
(function (ValidateOn) {
|
|
@@ -66,8 +67,8 @@ export const toFtInput = applyMixinOnce(Symbol("toFtInput"), function (ElementCl
|
|
|
66
67
|
}
|
|
67
68
|
}
|
|
68
69
|
triggerValidation() {
|
|
69
|
-
this.errorMessages = this.
|
|
70
|
-
this.warningMessages = this.
|
|
70
|
+
this.errorMessages = processValidationRules(this.value, ([...this.errorRules, ...this.additionalErrorRules]));
|
|
71
|
+
this.warningMessages = processValidationRules(this.value, ([...this.warningRules, ...this.additionalWarningRules]));
|
|
71
72
|
this.status = this.resolveStatus();
|
|
72
73
|
this.dispatchEvent(new InputValidationEvent(this.status));
|
|
73
74
|
}
|
|
@@ -96,11 +97,6 @@ export const toFtInput = applyMixinOnce(Symbol("toFtInput"), function (ElementCl
|
|
|
96
97
|
: this.warningMessages.length ? Status.warning
|
|
97
98
|
: Status.default;
|
|
98
99
|
}
|
|
99
|
-
processRules(rules) {
|
|
100
|
-
return rules.map((r) => r(this.value))
|
|
101
|
-
.filter((s) => s !== true)
|
|
102
|
-
.map((e) => e);
|
|
103
|
-
}
|
|
104
100
|
}
|
|
105
101
|
__decorate([
|
|
106
102
|
property()
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export type ValidationRule<V> = (value?: V) => true | string;
|
|
2
2
|
export declare const ValidationRules: {
|
|
3
3
|
required: (message: string) => ValidationRule<string>;
|
|
4
|
+
regex: (regex: RegExp, message: string) => ValidationRule<string>;
|
|
4
5
|
email: (message: string) => ValidationRule<string>;
|
|
5
6
|
url: (message: string) => ValidationRule<string>;
|
|
6
7
|
};
|
|
8
|
+
export declare function processValidationRules<V>(value: V | undefined, rules: ValidationRule<V>[]): string[];
|
|
@@ -1,13 +1,30 @@
|
|
|
1
|
-
const URL_REGEX = /^
|
|
1
|
+
const URL_REGEX = /^https?:\/\//;
|
|
2
2
|
const EMAIL_REGEX = /^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/;
|
|
3
|
+
function testRegex(regex, message, v) {
|
|
4
|
+
if (!v) {
|
|
5
|
+
return true;
|
|
6
|
+
}
|
|
7
|
+
if (!regex.test(v)) {
|
|
8
|
+
return message;
|
|
9
|
+
}
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
3
12
|
export const ValidationRules = {
|
|
4
13
|
required: function (message) {
|
|
5
|
-
return (v) => (!!v || message);
|
|
14
|
+
return (v) => (!!(v === null || v === void 0 ? void 0 : v.trim()) || message);
|
|
15
|
+
},
|
|
16
|
+
regex: function (regex, message) {
|
|
17
|
+
return (v) => testRegex(regex, message, v);
|
|
6
18
|
},
|
|
7
19
|
email: function (message) {
|
|
8
|
-
return (v) => (
|
|
20
|
+
return (v) => testRegex(EMAIL_REGEX, message, v);
|
|
9
21
|
},
|
|
10
22
|
url: function (message) {
|
|
11
|
-
return (v) => (
|
|
23
|
+
return (v) => testRegex(URL_REGEX, message, v);
|
|
12
24
|
},
|
|
13
25
|
};
|
|
26
|
+
export function processValidationRules(value, rules) {
|
|
27
|
+
return rules.map((r) => r(value))
|
|
28
|
+
.filter((s) => s !== true)
|
|
29
|
+
.map((e) => e);
|
|
30
|
+
}
|