not-bulma 1.0.52 → 1.0.54
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/package.json +1 -1
- package/src/elements/form/index.js +2 -0
- package/src/elements/form/ui.range.logarithmic.svelte +138 -0
- package/src/frame/components/form/form.js +29 -0
- package/src/frame/components/form/form.rules.js +45 -0
- package/src/frame/components/form/index.js +9 -1
- package/src/frame/components/index.js +2 -0
package/package.json
CHANGED
|
@@ -14,6 +14,7 @@ import UITelephone from "./ui.telephone.svelte";
|
|
|
14
14
|
import UITextarea from "./ui.textarea.svelte";
|
|
15
15
|
import UITextfield from "./ui.textfield.svelte";
|
|
16
16
|
import UIRange from "./ui.range.svelte";
|
|
17
|
+
import UIRangeLogarithmic from "./ui.range.logarithmic.svelte";
|
|
17
18
|
import UINumber from "./ui.number.svelte";
|
|
18
19
|
|
|
19
20
|
export {
|
|
@@ -33,5 +34,6 @@ export {
|
|
|
33
34
|
UITextarea,
|
|
34
35
|
UITextfield,
|
|
35
36
|
UIRange,
|
|
37
|
+
UIRangeLogarithmic,
|
|
36
38
|
UINumber,
|
|
37
39
|
};
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
const MAX = Number.MAX_SAFE_INTEGER;
|
|
3
|
+
import "bulma-slider/src/sass/index.sass";
|
|
4
|
+
|
|
5
|
+
import UICommon from "not-bulma/src/elements/common.js";
|
|
6
|
+
import ErrorsList from "not-bulma/src/elements/various/ui.errors.list.svelte";
|
|
7
|
+
import { createEventDispatcher, onMount } from "svelte";
|
|
8
|
+
let dispatch = createEventDispatcher();
|
|
9
|
+
|
|
10
|
+
export let inputStarted = false;
|
|
11
|
+
export let value = 10;
|
|
12
|
+
export let min = 0;
|
|
13
|
+
export let max = 100;
|
|
14
|
+
export let step = 1;
|
|
15
|
+
export let tickmarks = false;
|
|
16
|
+
export let placeholder = "range placeholder";
|
|
17
|
+
export let fieldname = "range";
|
|
18
|
+
export let icon = false;
|
|
19
|
+
export let required = true;
|
|
20
|
+
export let disabled = false;
|
|
21
|
+
export let readonly = false;
|
|
22
|
+
export let valid = true;
|
|
23
|
+
export let validated = false;
|
|
24
|
+
export let errors = false;
|
|
25
|
+
export let formErrors = false;
|
|
26
|
+
export let formLevelError = false;
|
|
27
|
+
|
|
28
|
+
$: iconClasses = (icon ? " has-icons-left " : "") + " has-icons-right ";
|
|
29
|
+
$: allErrors = [].concat(
|
|
30
|
+
errors ? errors : [],
|
|
31
|
+
formErrors ? formErrors : []
|
|
32
|
+
);
|
|
33
|
+
$: showErrors = !(validated && valid) && inputStarted;
|
|
34
|
+
$: invalid = valid === false || formLevelError;
|
|
35
|
+
$: validationClasses =
|
|
36
|
+
valid === true || !inputStarted
|
|
37
|
+
? UICommon.CLASS_OK
|
|
38
|
+
: UICommon.CLASS_ERR;
|
|
39
|
+
|
|
40
|
+
function onBlur(ev) {
|
|
41
|
+
const val = getLogarithmicValue(ev.currentTarget.value);
|
|
42
|
+
value = val;
|
|
43
|
+
let data = {
|
|
44
|
+
field: fieldname,
|
|
45
|
+
value,
|
|
46
|
+
};
|
|
47
|
+
inputStarted = true;
|
|
48
|
+
dispatch("change", data);
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function onInput(ev) {
|
|
53
|
+
const val = getLogarithmicValue(
|
|
54
|
+
Math.round(parseInt(ev.currentTarget.value))
|
|
55
|
+
);
|
|
56
|
+
value = val;
|
|
57
|
+
let data = {
|
|
58
|
+
field: fieldname,
|
|
59
|
+
value,
|
|
60
|
+
};
|
|
61
|
+
inputStarted = true;
|
|
62
|
+
dispatch("change", data);
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
let posMin = 0,
|
|
67
|
+
posMax = 100,
|
|
68
|
+
lMin = 0,
|
|
69
|
+
lMax = 100,
|
|
70
|
+
lScale = 10,
|
|
71
|
+
lStep = 0.1,
|
|
72
|
+
posValue = 1;
|
|
73
|
+
|
|
74
|
+
onMount(() => {
|
|
75
|
+
lMin = Math.log(min || 1);
|
|
76
|
+
lMax = Math.log(max || MAX);
|
|
77
|
+
lScale = (lMax - lMin) / (posMax - posMin);
|
|
78
|
+
posValue = getLogarithmicPosition(parseInt(value));
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
function getLogarithmicValue(pos) {
|
|
82
|
+
pos = parseInt(pos);
|
|
83
|
+
return Math.round(Math.exp((pos - posMin) * lScale + lMin));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function getLogarithmicPosition(val) {
|
|
87
|
+
val = parseInt(val);
|
|
88
|
+
return min + (Math.log(val) - lMin) / lScale;
|
|
89
|
+
}
|
|
90
|
+
</script>
|
|
91
|
+
|
|
92
|
+
<div class="control {iconClasses}">
|
|
93
|
+
{#if readonly}
|
|
94
|
+
<p>{value}</p>
|
|
95
|
+
{:else}
|
|
96
|
+
<input
|
|
97
|
+
id="form-field-range-{fieldname}"
|
|
98
|
+
class="input big-number slider has-output is-fullwidth is-success {validationClasses}"
|
|
99
|
+
type="range"
|
|
100
|
+
name={fieldname}
|
|
101
|
+
min={posMin}
|
|
102
|
+
max={posMax}
|
|
103
|
+
step={lStep}
|
|
104
|
+
list="form-field-range-{fieldname}-tickmarks"
|
|
105
|
+
{invalid}
|
|
106
|
+
{disabled}
|
|
107
|
+
{required}
|
|
108
|
+
{readonly}
|
|
109
|
+
{placeholder}
|
|
110
|
+
bind:value={posValue}
|
|
111
|
+
autocomplete={fieldname}
|
|
112
|
+
aria-controls="input-field-helper-{fieldname}"
|
|
113
|
+
on:change={onBlur}
|
|
114
|
+
on:input={onInput}
|
|
115
|
+
aria-describedby="input-field-helper-{fieldname}"
|
|
116
|
+
/>
|
|
117
|
+
<output for="form-field-range-{fieldname}">{value}</output>
|
|
118
|
+
{#if Array.isArray(tickmarks) && tickmarks.length}
|
|
119
|
+
<datalist id="form-field-range-{fieldname}-tickmarks">
|
|
120
|
+
{#each tickmarks as tickmark}
|
|
121
|
+
<option value={tickmark.value} label={tickmark.label} />
|
|
122
|
+
{/each}
|
|
123
|
+
</datalist>
|
|
124
|
+
{/if}
|
|
125
|
+
|
|
126
|
+
{#if icon}
|
|
127
|
+
<span class="icon is-small is-left"
|
|
128
|
+
><i class="fas fa-{icon}" /></span
|
|
129
|
+
>
|
|
130
|
+
{/if}
|
|
131
|
+
{/if}
|
|
132
|
+
</div>
|
|
133
|
+
<ErrorsList
|
|
134
|
+
bind:errors={allErrors}
|
|
135
|
+
bind:show={showErrors}
|
|
136
|
+
bind:classes={validationClasses}
|
|
137
|
+
id="input-field-helper-{fieldname}"
|
|
138
|
+
/>
|
|
@@ -8,6 +8,7 @@ import notBase from "../../base";
|
|
|
8
8
|
import UICommon from "../../../elements/common.js";
|
|
9
9
|
import FormHelpers from "./form.helpers.js";
|
|
10
10
|
import UIFormComponent from "./form.svelte";
|
|
11
|
+
import notFormRules from "./form.rules.js";
|
|
11
12
|
|
|
12
13
|
import { DEFAULT_STATUS_SUCCESS, DEFAULT_STATUS_ERROR } from "../../const";
|
|
13
14
|
|
|
@@ -141,6 +142,34 @@ class notForm extends notBase {
|
|
|
141
142
|
this.#form.$on("submit", (ev) => this.submit(ev.detail));
|
|
142
143
|
this.#form.$on("reject", () => this.reject());
|
|
143
144
|
this.#form.$on("error", ({ detail }) => this.emit("error", detail));
|
|
145
|
+
this.#bindMasterSlaveEvents();
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
#bindMasterSlaveEvents() {
|
|
149
|
+
const masters = this.getOptions("masters", false);
|
|
150
|
+
if (!masters) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
for (let master in masters) {
|
|
154
|
+
const rules = masters[master];
|
|
155
|
+
for (let ruleName in rules) {
|
|
156
|
+
const ruleSlaves = rules[ruleName];
|
|
157
|
+
this.#addMasterSlaveEvents(ruleName, master, ruleSlaves);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
#addMasterSlaveEvents(rule, master, slaves = []) {
|
|
163
|
+
this.on(`change.${master}`, (value) => {
|
|
164
|
+
this.#execSlaveRule(rule, slaves, value);
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
#execSlaveRule(rule, slaves, value) {
|
|
169
|
+
const cmd = notFormRules.exec(rule, value);
|
|
170
|
+
slaves.forEach((slaveField) => {
|
|
171
|
+
this.updateField(slaveField, cmd);
|
|
172
|
+
});
|
|
144
173
|
}
|
|
145
174
|
|
|
146
175
|
async validateForm() {
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const DEFAULT_RULES = {
|
|
2
|
+
notReadonly(v) {
|
|
3
|
+
return {
|
|
4
|
+
readonly: !v,
|
|
5
|
+
};
|
|
6
|
+
},
|
|
7
|
+
readonly(v) {
|
|
8
|
+
return {
|
|
9
|
+
readonly: v,
|
|
10
|
+
};
|
|
11
|
+
},
|
|
12
|
+
enable(v) {
|
|
13
|
+
return {
|
|
14
|
+
disabled: !v,
|
|
15
|
+
};
|
|
16
|
+
},
|
|
17
|
+
disable(v) {
|
|
18
|
+
return {
|
|
19
|
+
disabled: v,
|
|
20
|
+
};
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export default class notFormRules {
|
|
25
|
+
static #RULES = { ...DEFAULT_RULES };
|
|
26
|
+
|
|
27
|
+
static add(name, func) {
|
|
28
|
+
if (!Object.hasOwn(this.#RULES, name)) {
|
|
29
|
+
this.#RULES[name] = func;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
static remove(name) {
|
|
34
|
+
if (
|
|
35
|
+
Object.hasOwn(this.#RULES, name) &&
|
|
36
|
+
!Object.keys(DEFAULT_RULES).includes(name)
|
|
37
|
+
) {
|
|
38
|
+
delete this.#RULES[name];
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
static exec(name, value) {
|
|
43
|
+
return this.#RULES[name](value);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import notFormUtils from "./utils";
|
|
2
2
|
import notFormHelpers from "./form.helpers";
|
|
3
3
|
import notForm from "./form";
|
|
4
|
+
import notFormRules from "./form.rules";
|
|
4
5
|
import notFormSet from "./form.set";
|
|
5
6
|
import UIForm from "./form.svelte";
|
|
6
7
|
|
|
7
|
-
export {
|
|
8
|
+
export {
|
|
9
|
+
UIForm,
|
|
10
|
+
notForm,
|
|
11
|
+
notFormRules,
|
|
12
|
+
notFormSet,
|
|
13
|
+
notFormUtils,
|
|
14
|
+
notFormHelpers,
|
|
15
|
+
};
|
|
@@ -4,6 +4,7 @@ import notActionUI from "./action/action.ui.js";
|
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
6
|
notForm,
|
|
7
|
+
notFormRules,
|
|
7
8
|
notFormSet,
|
|
8
9
|
notFormUtils,
|
|
9
10
|
notFormHelpers,
|
|
@@ -19,6 +20,7 @@ export {
|
|
|
19
20
|
notTable,
|
|
20
21
|
UIForm,
|
|
21
22
|
notForm,
|
|
23
|
+
notFormRules,
|
|
22
24
|
notFormSet,
|
|
23
25
|
notFormUtils,
|
|
24
26
|
notFormHelpers,
|