@iyulab/lowline-form 0.1.0 → 0.3.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.
- package/LICENSE +21 -0
- package/README.md +5 -2
- package/dist/bundle/lowline-form.bundle.js +14 -8
- package/dist/client.d.ts +5 -2
- package/dist/client.js +5 -2
- package/dist/headless.d.ts +3 -0
- package/dist/headless.js +5 -0
- package/dist/index.d.ts +1 -3
- package/dist/index.js +1 -3
- package/dist/lowline-form.d.ts +9 -0
- package/dist/lowline-form.js +12 -2
- package/package.json +10 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 iyulab
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -22,13 +22,16 @@ routes (`MapLowline` in .NET).
|
|
|
22
22
|
| `rate` | How often a field's answer is held back to check it, from 0 to 1 (one in twenty by default). |
|
|
23
23
|
| `strings` | The words the form shows, in the host's language. |
|
|
24
24
|
|
|
25
|
-
`save()` sends the values with the account of what was shown, taken and turned down, and fires `lowline-saved`;
|
|
25
|
+
`save()` sends the values with the account of what was shown, taken and turned down, and fires `lowline-saved`; a
|
|
26
|
+
host that stores the record through its own API calls `settle()` after its save instead, which sends only the account
|
|
27
|
+
and has the host's engine learn the record as stored (`Saved` in .NET);
|
|
26
28
|
`fill(text)` offers the host model's values in their fields. A field the records cannot answer yet is judged by the
|
|
27
29
|
host's model when it has one (`judge`): asked once for the values it reads, shown in the field while the person writes
|
|
28
30
|
on, never put in on its own. When the routes do not answer, `lowline-unavailable` fires and the form is filled in by
|
|
29
31
|
hand. Nothing is counted in the browser: the host's engine counts what it is sent.
|
|
30
32
|
|
|
31
|
-
`Draft`, `Session` and `LowlineClient`
|
|
33
|
+
A host that draws its own form imports `Draft`, `Session` and `LowlineClient` from `@iyulab/lowline-form/headless`,
|
|
34
|
+
which brings in neither Lit nor formdown and registers no element (the package root carries them too, with the element).
|
|
32
35
|
|
|
33
36
|
The package is `@iyulab/lowline-form`, with Lit and formdown as dependencies. A page with no build step takes the one
|
|
34
37
|
file in it that carries both: `dist/bundle/lowline-form.bundle.js`.
|
|
@@ -155,8 +155,8 @@ var s = class extends Error {
|
|
|
155
155
|
settle(e, t, n, r) {
|
|
156
156
|
return this.post(e, "settle", {
|
|
157
157
|
id: t,
|
|
158
|
-
saved:
|
|
159
|
-
draft:
|
|
158
|
+
saved: r,
|
|
159
|
+
draft: n
|
|
160
160
|
});
|
|
161
161
|
}
|
|
162
162
|
fill(e, t, n) {
|
|
@@ -11144,17 +11144,23 @@ var Fl = 300, $ = class extends Ge {
|
|
|
11144
11144
|
values() {
|
|
11145
11145
|
return r(this.formdown?.data ?? this.data);
|
|
11146
11146
|
}
|
|
11147
|
-
|
|
11147
|
+
save() {
|
|
11148
|
+
return this.settleWith(!0);
|
|
11149
|
+
}
|
|
11150
|
+
settle() {
|
|
11151
|
+
return this.settleWith(!1);
|
|
11152
|
+
}
|
|
11153
|
+
async settleWith(e) {
|
|
11148
11154
|
if (!this.session || !this.form || !this.record) throw Error("lowline-form needs a form and a record to save");
|
|
11149
|
-
let
|
|
11150
|
-
return this.session.saved(
|
|
11155
|
+
let t = this.values(), n = await this.client.settle(this.form, this.record, this.session.draft, e ? t : void 0);
|
|
11156
|
+
return this.session.saved(t), this.dispatchEvent(new CustomEvent("lowline-saved", {
|
|
11151
11157
|
detail: {
|
|
11152
|
-
...
|
|
11153
|
-
values:
|
|
11158
|
+
...n,
|
|
11159
|
+
values: t
|
|
11154
11160
|
},
|
|
11155
11161
|
bubbles: !0,
|
|
11156
11162
|
composed: !0
|
|
11157
|
-
})),
|
|
11163
|
+
})), n;
|
|
11158
11164
|
}
|
|
11159
11165
|
async fill(e) {
|
|
11160
11166
|
let t = this.session;
|
package/dist/client.d.ts
CHANGED
|
@@ -16,8 +16,11 @@ export declare class LowlineClient {
|
|
|
16
16
|
constructor(src: string, fetcher?: typeof fetch);
|
|
17
17
|
/** What to show for each open decided field of record `id`, given its values so far. */
|
|
18
18
|
propose(form: string, id: string, values: Values): Promise<Proposal[]>;
|
|
19
|
-
/**
|
|
20
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Settles record `id` with the draft kept while it was written: saves it holding `saved`, or — left out, for a host
|
|
21
|
+
* that stores its records through its own API and reads them back (`Saved` in .NET) — learns what the host stored.
|
|
22
|
+
*/
|
|
23
|
+
settle(form: string, id: string, draft: Draft, saved?: Values): Promise<{
|
|
21
24
|
id: string;
|
|
22
25
|
settledAt: string;
|
|
23
26
|
}>;
|
package/dist/client.js
CHANGED
|
@@ -20,8 +20,11 @@ export class LowlineClient {
|
|
|
20
20
|
propose(form, id, values) {
|
|
21
21
|
return this.post(form, 'propose', { id, values });
|
|
22
22
|
}
|
|
23
|
-
/**
|
|
24
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Settles record `id` with the draft kept while it was written: saves it holding `saved`, or — left out, for a host
|
|
25
|
+
* that stores its records through its own API and reads them back (`Saved` in .NET) — learns what the host stored.
|
|
26
|
+
*/
|
|
27
|
+
settle(form, id, draft, saved) {
|
|
25
28
|
return this.post(form, 'settle', { id, saved, draft });
|
|
26
29
|
}
|
|
27
30
|
/** What the host's model makes of `text` for the fields of record values still empty — 404 when the host gave none. */
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { Draft, valuesOf, type Suggestion, type Value, type Values } from './draft.js';
|
|
2
|
+
export { Session, englishStrings, type Abstain, type Basis, type FieldState, type Proposal, type Round, type Strings } from './session.js';
|
|
3
|
+
export { LowlineClient, LowlineError } from './client.js';
|
package/dist/headless.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// What a host drawing its own form needs — the draft, the session and the client — without the element: nothing here
|
|
2
|
+
// imports Lit or formdown, or touches the DOM, so it loads in a server or a worker too.
|
|
3
|
+
export { Draft, valuesOf } from './draft.js';
|
|
4
|
+
export { Session, englishStrings } from './session.js';
|
|
5
|
+
export { LowlineClient, LowlineError } from './client.js';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
export { Session, englishStrings, type Abstain, type Basis, type FieldState, type Proposal, type Round, type Strings } from './session.js';
|
|
3
|
-
export { LowlineClient, LowlineError } from './client.js';
|
|
1
|
+
export * from './headless.js';
|
|
4
2
|
export { LowlineForm } from './lowline-form.js';
|
package/dist/index.js
CHANGED
package/dist/lowline-form.d.ts
CHANGED
|
@@ -47,6 +47,15 @@ export declare class LowlineForm extends LitElement {
|
|
|
47
47
|
id: string;
|
|
48
48
|
settledAt: string;
|
|
49
49
|
}>;
|
|
50
|
+
/**
|
|
51
|
+
* For a host that stores the record through its own API first: sends only the account of what was shown and done,
|
|
52
|
+
* and the host's engine learns the record as the host stored it (`Saved` in .NET). What is written next starts here.
|
|
53
|
+
*/
|
|
54
|
+
settle(): Promise<{
|
|
55
|
+
id: string;
|
|
56
|
+
settledAt: string;
|
|
57
|
+
}>;
|
|
58
|
+
private settleWith;
|
|
50
59
|
/**
|
|
51
60
|
* Fills the record from `text` — what the person wrote or a picture's description — through the host's model: each
|
|
52
61
|
* value it gives is offered in its field for the person to take. Nothing is put in on its own.
|
package/dist/lowline-form.js
CHANGED
|
@@ -100,11 +100,21 @@ let LowlineForm = class LowlineForm extends LitElement {
|
|
|
100
100
|
return valuesOf(this.formdown?.data ?? this.data);
|
|
101
101
|
}
|
|
102
102
|
/** Saves the record as it stands, with the account of what was shown and done; what is written next starts here. */
|
|
103
|
-
|
|
103
|
+
save() {
|
|
104
|
+
return this.settleWith(true);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* For a host that stores the record through its own API first: sends only the account of what was shown and done,
|
|
108
|
+
* and the host's engine learns the record as the host stored it (`Saved` in .NET). What is written next starts here.
|
|
109
|
+
*/
|
|
110
|
+
settle() {
|
|
111
|
+
return this.settleWith(false);
|
|
112
|
+
}
|
|
113
|
+
async settleWith(sendValues) {
|
|
104
114
|
if (!this.session || !this.form || !this.record)
|
|
105
115
|
throw new Error('lowline-form needs a form and a record to save');
|
|
106
116
|
const values = this.values();
|
|
107
|
-
const saved = await this.client.settle(this.form, this.record,
|
|
117
|
+
const saved = await this.client.settle(this.form, this.record, this.session.draft, sendValues ? values : undefined);
|
|
108
118
|
this.session.saved(values);
|
|
109
119
|
this.dispatchEvent(new CustomEvent('lowline-saved', { detail: { ...saved, values }, bubbles: true, composed: true }));
|
|
110
120
|
return saved;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iyulab/lowline-form",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "The Lowline form element: a formdown form whose decided fields are suggested from the records people confirmed, talking to a Lowline host's routes.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -15,8 +15,17 @@
|
|
|
15
15
|
".": {
|
|
16
16
|
"types": "./dist/index.d.ts",
|
|
17
17
|
"import": "./dist/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./headless": {
|
|
20
|
+
"types": "./dist/headless.d.ts",
|
|
21
|
+
"import": "./dist/headless.js"
|
|
18
22
|
}
|
|
19
23
|
},
|
|
24
|
+
"sideEffects": [
|
|
25
|
+
"./dist/index.js",
|
|
26
|
+
"./dist/lowline-form.js",
|
|
27
|
+
"./dist/bundle/*"
|
|
28
|
+
],
|
|
20
29
|
"files": [
|
|
21
30
|
"dist"
|
|
22
31
|
],
|