@formancy/builder-core 0.1.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 +202 -0
- package/NOTICE +4 -0
- package/dist/index.d.mts +76 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +283 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +47 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { SchemaError } from "@formancy/spec/validate";
|
|
2
|
+
import { FieldDef, FormSchema, LogicRule } from "@formancy/spec";
|
|
3
|
+
//#region src/session.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* The headless document engine under the form builder.
|
|
6
|
+
*
|
|
7
|
+
* Three rules shape everything here.
|
|
8
|
+
*
|
|
9
|
+
* **A session may never hold a document the validator rejects.** Commands are
|
|
10
|
+
* applied to a copy, validated, and only then committed; a command that would
|
|
11
|
+
* produce an invalid document is refused with the validator's own
|
|
12
|
+
* author-facing message and the held document is untouched. That is why
|
|
13
|
+
* `canPublish()` is true by construction rather than by hope — and why legality
|
|
14
|
+
* is decided by *trying* a command rather than by a second implementation of
|
|
15
|
+
* the validator's rules, which would drift from it.
|
|
16
|
+
*
|
|
17
|
+
* **The document is frozen and copied at every boundary.** A builder UI is a
|
|
18
|
+
* projection of this state, and a projection that can reach in and mutate the
|
|
19
|
+
* model is how undo stops working.
|
|
20
|
+
*
|
|
21
|
+
* **Commands, never gestures.** Insert, move, remove, rename, set. WCAG 2.2
|
|
22
|
+
* requires every drag operation to have a keyboard equivalent, so the keyboard
|
|
23
|
+
* path is the API and a drag layer is sugar over it — not the other way round,
|
|
24
|
+
* which is how the keyboard path ends up an afterthought nobody finishes.
|
|
25
|
+
*/
|
|
26
|
+
interface Refusal {
|
|
27
|
+
ok: false;
|
|
28
|
+
/** JSON Pointer into the document, as the validator reports it. */
|
|
29
|
+
path: string;
|
|
30
|
+
message: string;
|
|
31
|
+
}
|
|
32
|
+
type CommandOutcome = {
|
|
33
|
+
ok: true;
|
|
34
|
+
document: FormSchema;
|
|
35
|
+
} | Refusal;
|
|
36
|
+
/** Where a field goes: the key path of its container, and a position in it. */
|
|
37
|
+
interface Location {
|
|
38
|
+
parent: readonly string[];
|
|
39
|
+
index: number;
|
|
40
|
+
}
|
|
41
|
+
interface BuilderSession {
|
|
42
|
+
/** The current document: frozen, and never the caller's object. */
|
|
43
|
+
document(): FormSchema;
|
|
44
|
+
/** A mutable deep copy, safe to hand to anything. */
|
|
45
|
+
exportDocument(): FormSchema;
|
|
46
|
+
/** Increments once per accepted command, undo or redo. */
|
|
47
|
+
revision(): number;
|
|
48
|
+
canUndo(): boolean;
|
|
49
|
+
canRedo(): boolean;
|
|
50
|
+
undo(): boolean;
|
|
51
|
+
redo(): boolean;
|
|
52
|
+
/** The validator's verdict on the held document. Valid by construction. */
|
|
53
|
+
canPublish(): {
|
|
54
|
+
valid: boolean;
|
|
55
|
+
errors: SchemaError[];
|
|
56
|
+
};
|
|
57
|
+
/** One notification per accepted command, undo or redo. */
|
|
58
|
+
subscribe(listener: () => void): () => void;
|
|
59
|
+
insertField(location: Location, def: FieldDef): CommandOutcome;
|
|
60
|
+
removeField(keyPath: readonly string[]): CommandOutcome;
|
|
61
|
+
moveField(from: readonly string[], to: Location): CommandOutcome;
|
|
62
|
+
renameField(keyPath: readonly string[], newKey: string): CommandOutcome;
|
|
63
|
+
setFieldProperty(keyPath: readonly string[], property: string, value: unknown): CommandOutcome;
|
|
64
|
+
addRule(rule: LogicRule): CommandOutcome;
|
|
65
|
+
updateRule(index: number, rule: LogicRule): CommandOutcome;
|
|
66
|
+
removeRule(index: number): CommandOutcome;
|
|
67
|
+
/**
|
|
68
|
+
* Every location a field may legally land: a palette entry (pass a
|
|
69
|
+
* definition) or an existing field being moved (pass its key path).
|
|
70
|
+
*/
|
|
71
|
+
validTargets(what: FieldDef | readonly string[]): Location[];
|
|
72
|
+
}
|
|
73
|
+
export declare function createBuilderSession(initial: FormSchema): BuilderSession;
|
|
74
|
+
//#endregion
|
|
75
|
+
export type { BuilderSession, CommandOutcome, Location, Refusal };
|
|
76
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/session.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;UA0BiB;EACf;;EAEA;EACA;;KAGU;EAAmB;EAAU,UAAU;IAAe;;UAGjD;EACf;EACA;;UAGe;;EAEf,YAAY;;EAEZ,kBAAkB;;EAElB;EACA;EACA;EACA;EACA;;EAEA;IAAgB;IAAgB,QAAQ;;;EAExC,UAAU;EAEV,YAAY,UAAU,UAAU,KAAK,WAAW;EAChD,YAAY,6BAA6B;EACzC,UAAU,yBAAyB,IAAI,WAAW;EAClD,YAAY,4BAA4B,iBAAiB;EACzD,iBAAiB,4BAA4B,kBAAkB,iBAAiB;EAChF,QAAQ,MAAM,YAAY;EAC1B,WAAW,eAAe,MAAM,YAAY;EAC5C,WAAW,gBAAgB;;;;;EAM3B,aAAa,MAAM,+BAA+B;;wBAKpC,qBAAqB,SAAS,aAAa"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import { validateSchema } from "@formancy/spec/validate";
|
|
2
|
+
//#region src/session.ts
|
|
3
|
+
const CONTAINER_TYPES = /* @__PURE__ */ new Set([
|
|
4
|
+
"group",
|
|
5
|
+
"page",
|
|
6
|
+
"repeater"
|
|
7
|
+
]);
|
|
8
|
+
function createBuilderSession(initial) {
|
|
9
|
+
const opened = deepFreeze(copy(initial));
|
|
10
|
+
const verdict = verdictFor(opened);
|
|
11
|
+
if (!verdict.valid) throw new Error(`Cannot open this document in a builder session: ${verdict.errors.map((error) => `${error.path} ${error.message}`).join("; ")}`);
|
|
12
|
+
/**
|
|
13
|
+
* The keys every field had when the session opened. A rename declares
|
|
14
|
+
* `renamedFrom` against THIS, never against the previous key: chaining
|
|
15
|
+
* would point a migration at an interim key no submission ever used.
|
|
16
|
+
*/
|
|
17
|
+
const baselineKeys = /* @__PURE__ */ new Map();
|
|
18
|
+
indexBaseline(opened.model.fields, baselineKeys);
|
|
19
|
+
const past = [];
|
|
20
|
+
const future = [];
|
|
21
|
+
let present = opened;
|
|
22
|
+
let revision = 0;
|
|
23
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
24
|
+
/** Identity survives edits by data path, so a renamed field keeps its
|
|
25
|
+
* baseline. Keyed by the path a field had in the baseline document. */
|
|
26
|
+
const baselineByCurrentKey = /* @__PURE__ */ new Map();
|
|
27
|
+
seedBaselineByKey(opened.model.fields, baselineByCurrentKey);
|
|
28
|
+
function commit(candidate) {
|
|
29
|
+
const check = verdictFor(candidate);
|
|
30
|
+
if (!check.valid) {
|
|
31
|
+
const first = check.errors[0];
|
|
32
|
+
return {
|
|
33
|
+
ok: false,
|
|
34
|
+
path: first.path,
|
|
35
|
+
message: first.message
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
past.push(present);
|
|
39
|
+
future.length = 0;
|
|
40
|
+
present = deepFreeze(candidate);
|
|
41
|
+
revision += 1;
|
|
42
|
+
for (const listener of [...listeners]) listener();
|
|
43
|
+
return {
|
|
44
|
+
ok: true,
|
|
45
|
+
document: present
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function refuse(path, message) {
|
|
49
|
+
return {
|
|
50
|
+
ok: false,
|
|
51
|
+
path,
|
|
52
|
+
message
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/** Apply `edit` to a working copy and commit if the validator agrees. */
|
|
56
|
+
function attempt(edit) {
|
|
57
|
+
const draft = copy(present);
|
|
58
|
+
const problem = edit(draft);
|
|
59
|
+
if (problem !== void 0) return problem;
|
|
60
|
+
return commit(draft);
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
document: () => present,
|
|
64
|
+
exportDocument: () => copy(present),
|
|
65
|
+
revision: () => revision,
|
|
66
|
+
canUndo: () => past.length > 0,
|
|
67
|
+
canRedo: () => future.length > 0,
|
|
68
|
+
undo() {
|
|
69
|
+
const previous = past.pop();
|
|
70
|
+
if (previous === void 0) return false;
|
|
71
|
+
future.push(present);
|
|
72
|
+
present = previous;
|
|
73
|
+
revision += 1;
|
|
74
|
+
for (const listener of [...listeners]) listener();
|
|
75
|
+
return true;
|
|
76
|
+
},
|
|
77
|
+
redo() {
|
|
78
|
+
const next = future.pop();
|
|
79
|
+
if (next === void 0) return false;
|
|
80
|
+
past.push(present);
|
|
81
|
+
present = next;
|
|
82
|
+
revision += 1;
|
|
83
|
+
for (const listener of [...listeners]) listener();
|
|
84
|
+
return true;
|
|
85
|
+
},
|
|
86
|
+
canPublish: () => verdictFor(present),
|
|
87
|
+
subscribe(listener) {
|
|
88
|
+
listeners.add(listener);
|
|
89
|
+
return () => listeners.delete(listener);
|
|
90
|
+
},
|
|
91
|
+
insertField(location, def) {
|
|
92
|
+
return attempt((draft) => {
|
|
93
|
+
const container = containerAt(draft, location.parent);
|
|
94
|
+
if (container === void 0) return refuse("/model/fields", `No container at "${location.parent.join(".")}".`);
|
|
95
|
+
container.splice(clampIndex(location.index, container.length), 0, copy(def));
|
|
96
|
+
});
|
|
97
|
+
},
|
|
98
|
+
removeField(keyPath) {
|
|
99
|
+
return attempt((draft) => {
|
|
100
|
+
const found = locate(draft, keyPath);
|
|
101
|
+
if (found === void 0) return refuse("/model/fields", `No field at "${keyPath.join(".")}".`);
|
|
102
|
+
found.siblings.splice(found.index, 1);
|
|
103
|
+
});
|
|
104
|
+
},
|
|
105
|
+
moveField(from, to) {
|
|
106
|
+
if (isPrefix(from, to.parent)) return refuse("/model/fields", `Cannot move "${from.join(".")}" inside itself or one of its own children.`);
|
|
107
|
+
return attempt((draft) => {
|
|
108
|
+
const found = locate(draft, from);
|
|
109
|
+
if (found === void 0) return refuse("/model/fields", `No field at "${from.join(".")}".`);
|
|
110
|
+
const [moved] = found.siblings.splice(found.index, 1);
|
|
111
|
+
const container = containerAt(draft, to.parent);
|
|
112
|
+
if (container === void 0) return refuse("/model/fields", `No container at "${to.parent.join(".")}".`);
|
|
113
|
+
container.splice(clampIndex(to.index, container.length), 0, moved);
|
|
114
|
+
});
|
|
115
|
+
},
|
|
116
|
+
renameField(keyPath, newKey) {
|
|
117
|
+
return attempt((draft) => {
|
|
118
|
+
const found = locate(draft, keyPath);
|
|
119
|
+
if (found === void 0) return refuse("/model/fields", `No field at "${keyPath.join(".")}".`);
|
|
120
|
+
const field = found.siblings[found.index];
|
|
121
|
+
const baseline = baselineByCurrentKey.get(field.key) ?? field.key;
|
|
122
|
+
field.key = newKey;
|
|
123
|
+
if (newKey === baseline) delete field.renamedFrom;
|
|
124
|
+
else field.renamedFrom = baseline;
|
|
125
|
+
baselineByCurrentKey.set(newKey, baseline);
|
|
126
|
+
});
|
|
127
|
+
},
|
|
128
|
+
setFieldProperty(keyPath, property, value) {
|
|
129
|
+
return attempt((draft) => {
|
|
130
|
+
const found = locate(draft, keyPath);
|
|
131
|
+
if (found === void 0) return refuse("/model/fields", `No field at "${keyPath.join(".")}".`);
|
|
132
|
+
const field = found.siblings[found.index];
|
|
133
|
+
if (value === void 0) delete field[property];
|
|
134
|
+
else field[property] = copy(value);
|
|
135
|
+
});
|
|
136
|
+
},
|
|
137
|
+
addRule(rule) {
|
|
138
|
+
return attempt((draft) => {
|
|
139
|
+
draft.logic = draft.logic ?? { rules: [] };
|
|
140
|
+
draft.logic.rules.push(copy(rule));
|
|
141
|
+
});
|
|
142
|
+
},
|
|
143
|
+
updateRule(index, rule) {
|
|
144
|
+
return attempt((draft) => {
|
|
145
|
+
const rules = draft.logic?.rules;
|
|
146
|
+
if (rules === void 0 || index < 0 || index >= rules.length) return refuse("/logic/rules", `No rule at index ${index}.`);
|
|
147
|
+
rules[index] = copy(rule);
|
|
148
|
+
});
|
|
149
|
+
},
|
|
150
|
+
removeRule(index) {
|
|
151
|
+
return attempt((draft) => {
|
|
152
|
+
const rules = draft.logic?.rules;
|
|
153
|
+
if (rules === void 0 || index < 0 || index >= rules.length) return refuse("/logic/rules", `No rule at index ${index}.`);
|
|
154
|
+
rules.splice(index, 1);
|
|
155
|
+
});
|
|
156
|
+
},
|
|
157
|
+
validTargets(what) {
|
|
158
|
+
const movingPath = Array.isArray(what) ? what : void 0;
|
|
159
|
+
const probe = movingPath === void 0 ? what : locate(present, movingPath)?.siblings[locate(present, movingPath).index];
|
|
160
|
+
if (probe === void 0) return [];
|
|
161
|
+
const targets = [];
|
|
162
|
+
for (const parent of containerPaths(present)) {
|
|
163
|
+
if (movingPath !== void 0 && isPrefix(movingPath, parent)) continue;
|
|
164
|
+
const draft = copy(present);
|
|
165
|
+
if (movingPath !== void 0) {
|
|
166
|
+
const found = locate(draft, movingPath);
|
|
167
|
+
if (found === void 0) continue;
|
|
168
|
+
found.siblings.splice(found.index, 1);
|
|
169
|
+
}
|
|
170
|
+
const container = containerAt(draft, parent);
|
|
171
|
+
if (container === void 0) continue;
|
|
172
|
+
container.push(movingPath === void 0 ? withUniqueKey(copy(probe), draft) : copy(probe));
|
|
173
|
+
if (verdictFor(draft).valid) targets.push({
|
|
174
|
+
parent,
|
|
175
|
+
index: container.length - 1
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
return targets;
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
/** The child list of the container at `keyPath` — the root list for []. */
|
|
183
|
+
function containerAt(document, keyPath) {
|
|
184
|
+
if (keyPath.length === 0) return document.model.fields;
|
|
185
|
+
const found = locate(document, keyPath);
|
|
186
|
+
if (found === void 0) return void 0;
|
|
187
|
+
const field = found.siblings[found.index];
|
|
188
|
+
if (!CONTAINER_TYPES.has(field.type)) return void 0;
|
|
189
|
+
field.fields = field.fields ?? [];
|
|
190
|
+
return field.fields;
|
|
191
|
+
}
|
|
192
|
+
function locate(document, keyPath) {
|
|
193
|
+
if (keyPath.length === 0) return void 0;
|
|
194
|
+
let siblings = document.model.fields;
|
|
195
|
+
for (let depth = 0; depth < keyPath.length; depth++) {
|
|
196
|
+
const index = siblings.findIndex((field) => field.key === keyPath[depth]);
|
|
197
|
+
if (index === -1) return void 0;
|
|
198
|
+
if (depth === keyPath.length - 1) return {
|
|
199
|
+
siblings,
|
|
200
|
+
index
|
|
201
|
+
};
|
|
202
|
+
const next = siblings[index].fields;
|
|
203
|
+
if (next === void 0) return void 0;
|
|
204
|
+
siblings = next;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
/** Every container's key path, root first. */
|
|
208
|
+
function containerPaths(document) {
|
|
209
|
+
const paths = [[]];
|
|
210
|
+
const walk = (fields, prefix) => {
|
|
211
|
+
for (const field of fields) {
|
|
212
|
+
if (!CONTAINER_TYPES.has(field.type)) continue;
|
|
213
|
+
const here = [...prefix, field.key];
|
|
214
|
+
paths.push(here);
|
|
215
|
+
walk(field.fields ?? [], here);
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
walk(document.model.fields, []);
|
|
219
|
+
return paths;
|
|
220
|
+
}
|
|
221
|
+
function isPrefix(prefix, candidate) {
|
|
222
|
+
if (prefix.length > candidate.length) return false;
|
|
223
|
+
return prefix.every((segment, index) => candidate[index] === segment);
|
|
224
|
+
}
|
|
225
|
+
function clampIndex(index, length) {
|
|
226
|
+
if (!Number.isInteger(index) || index < 0) return 0;
|
|
227
|
+
return Math.min(index, length);
|
|
228
|
+
}
|
|
229
|
+
/** A palette probe must not fail purely because its placeholder key is taken —
|
|
230
|
+
* validTargets answers "may this SHAPE go here", not "is this key free". */
|
|
231
|
+
function withUniqueKey(def, document) {
|
|
232
|
+
const taken = /* @__PURE__ */ new Set();
|
|
233
|
+
const walk = (fields) => {
|
|
234
|
+
for (const field of fields) {
|
|
235
|
+
taken.add(field.key);
|
|
236
|
+
walk(field.fields ?? []);
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
walk(document.model.fields);
|
|
240
|
+
let candidate = def.key;
|
|
241
|
+
let counter = 1;
|
|
242
|
+
while (taken.has(candidate)) candidate = `${def.key}_${counter++}`;
|
|
243
|
+
return {
|
|
244
|
+
...def,
|
|
245
|
+
key: candidate
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
function indexBaseline(fields, into) {
|
|
249
|
+
for (const field of fields) {
|
|
250
|
+
into.set(field, field.key);
|
|
251
|
+
indexBaseline(field.fields ?? [], into);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
function seedBaselineByKey(fields, into) {
|
|
255
|
+
for (const field of fields) {
|
|
256
|
+
into.set(field.key, field.renamedFrom ?? field.key);
|
|
257
|
+
seedBaselineByKey(field.fields ?? [], into);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
function verdictFor(document) {
|
|
261
|
+
const result = validateSchema(document);
|
|
262
|
+
return result.valid ? {
|
|
263
|
+
valid: true,
|
|
264
|
+
errors: []
|
|
265
|
+
} : {
|
|
266
|
+
valid: false,
|
|
267
|
+
errors: result.errors
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
/** JSON round-trip: a form document is JSON by definition, and this package
|
|
271
|
+
* runs without structuredClone in its lib on purpose. */
|
|
272
|
+
function copy(value) {
|
|
273
|
+
return JSON.parse(JSON.stringify(value));
|
|
274
|
+
}
|
|
275
|
+
function deepFreeze(value) {
|
|
276
|
+
if (value === null || typeof value !== "object") return value;
|
|
277
|
+
for (const nested of Object.values(value)) deepFreeze(nested);
|
|
278
|
+
return Object.freeze(value);
|
|
279
|
+
}
|
|
280
|
+
//#endregion
|
|
281
|
+
export { createBuilderSession };
|
|
282
|
+
|
|
283
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/session.ts"],"sourcesContent":["import type { FieldDef, FormSchema, LogicRule } from '@formancy/spec'\nimport { validateSchema } from '@formancy/spec/validate'\nimport type { SchemaError } from '@formancy/spec/validate'\n\n/**\n * The headless document engine under the form builder.\n *\n * Three rules shape everything here.\n *\n * **A session may never hold a document the validator rejects.** Commands are\n * applied to a copy, validated, and only then committed; a command that would\n * produce an invalid document is refused with the validator's own\n * author-facing message and the held document is untouched. That is why\n * `canPublish()` is true by construction rather than by hope — and why legality\n * is decided by *trying* a command rather than by a second implementation of\n * the validator's rules, which would drift from it.\n *\n * **The document is frozen and copied at every boundary.** A builder UI is a\n * projection of this state, and a projection that can reach in and mutate the\n * model is how undo stops working.\n *\n * **Commands, never gestures.** Insert, move, remove, rename, set. WCAG 2.2\n * requires every drag operation to have a keyboard equivalent, so the keyboard\n * path is the API and a drag layer is sugar over it — not the other way round,\n * which is how the keyboard path ends up an afterthought nobody finishes.\n */\nexport interface Refusal {\n ok: false\n /** JSON Pointer into the document, as the validator reports it. */\n path: string\n message: string\n}\n\nexport type CommandOutcome = { ok: true; document: FormSchema } | Refusal\n\n/** Where a field goes: the key path of its container, and a position in it. */\nexport interface Location {\n parent: readonly string[]\n index: number\n}\n\nexport interface BuilderSession {\n /** The current document: frozen, and never the caller's object. */\n document(): FormSchema\n /** A mutable deep copy, safe to hand to anything. */\n exportDocument(): FormSchema\n /** Increments once per accepted command, undo or redo. */\n revision(): number\n canUndo(): boolean\n canRedo(): boolean\n undo(): boolean\n redo(): boolean\n /** The validator's verdict on the held document. Valid by construction. */\n canPublish(): { valid: boolean; errors: SchemaError[] }\n /** One notification per accepted command, undo or redo. */\n subscribe(listener: () => void): () => void\n\n insertField(location: Location, def: FieldDef): CommandOutcome\n removeField(keyPath: readonly string[]): CommandOutcome\n moveField(from: readonly string[], to: Location): CommandOutcome\n renameField(keyPath: readonly string[], newKey: string): CommandOutcome\n setFieldProperty(keyPath: readonly string[], property: string, value: unknown): CommandOutcome\n addRule(rule: LogicRule): CommandOutcome\n updateRule(index: number, rule: LogicRule): CommandOutcome\n removeRule(index: number): CommandOutcome\n\n /**\n * Every location a field may legally land: a palette entry (pass a\n * definition) or an existing field being moved (pass its key path).\n */\n validTargets(what: FieldDef | readonly string[]): Location[]\n}\n\nconst CONTAINER_TYPES = new Set(['group', 'page', 'repeater'])\n\nexport function createBuilderSession(initial: FormSchema): BuilderSession {\n const opened = deepFreeze(copy(initial))\n const verdict = verdictFor(opened)\n if (!verdict.valid) {\n // Opening an invalid document would make every later refusal ambiguous:\n // the caller could not tell whether their command broke the form or merely\n // failed to fix it.\n throw new Error(\n `Cannot open this document in a builder session: ${verdict.errors\n .map((error) => `${error.path} ${error.message}`)\n .join('; ')}`,\n )\n }\n\n /**\n * The keys every field had when the session opened. A rename declares\n * `renamedFrom` against THIS, never against the previous key: chaining\n * would point a migration at an interim key no submission ever used.\n */\n const baselineKeys = new Map<FieldDef, string>()\n indexBaseline(opened.model.fields, baselineKeys)\n\n const past: FormSchema[] = []\n const future: FormSchema[] = []\n let present: FormSchema = opened\n let revision = 0\n const listeners = new Set<() => void>()\n\n /** Identity survives edits by data path, so a renamed field keeps its\n * baseline. Keyed by the path a field had in the baseline document. */\n const baselineByCurrentKey = new Map<string, string>()\n seedBaselineByKey(opened.model.fields, baselineByCurrentKey)\n\n function commit(candidate: FormSchema): CommandOutcome {\n const check = verdictFor(candidate)\n if (!check.valid) {\n const first = check.errors[0]!\n return { ok: false, path: first.path, message: first.message }\n }\n past.push(present)\n // A new command abandons the redo branch: redoing onto a different history\n // would replay an edit against a document it was never made against.\n future.length = 0\n present = deepFreeze(candidate)\n revision += 1\n for (const listener of [...listeners]) listener()\n return { ok: true, document: present }\n }\n\n function refuse(path: string, message: string): Refusal {\n return { ok: false, path, message }\n }\n\n /** Apply `edit` to a working copy and commit if the validator agrees. */\n function attempt(edit: (draft: FormSchema) => Refusal | undefined): CommandOutcome {\n const draft = copy(present)\n const problem = edit(draft)\n if (problem !== undefined) return problem\n return commit(draft)\n }\n\n return {\n document: () => present,\n exportDocument: () => copy(present),\n revision: () => revision,\n canUndo: () => past.length > 0,\n canRedo: () => future.length > 0,\n\n undo() {\n const previous = past.pop()\n if (previous === undefined) return false\n future.push(present)\n present = previous\n revision += 1\n for (const listener of [...listeners]) listener()\n return true\n },\n\n redo() {\n const next = future.pop()\n if (next === undefined) return false\n past.push(present)\n present = next\n revision += 1\n for (const listener of [...listeners]) listener()\n return true\n },\n\n canPublish: () => verdictFor(present),\n\n subscribe(listener) {\n listeners.add(listener)\n return () => listeners.delete(listener)\n },\n\n insertField(location, def) {\n return attempt((draft) => {\n const container = containerAt(draft, location.parent)\n if (container === undefined) {\n return refuse('/model/fields', `No container at \"${location.parent.join('.')}\".`)\n }\n container.splice(clampIndex(location.index, container.length), 0, copy(def))\n return undefined\n })\n },\n\n removeField(keyPath) {\n return attempt((draft) => {\n const found = locate(draft, keyPath)\n if (found === undefined) return refuse('/model/fields', `No field at \"${keyPath.join('.')}\".`)\n found.siblings.splice(found.index, 1)\n return undefined\n })\n },\n\n moveField(from, to) {\n if (isPrefix(from, to.parent)) {\n return refuse(\n '/model/fields',\n `Cannot move \"${from.join('.')}\" inside itself or one of its own children.`,\n )\n }\n return attempt((draft) => {\n const found = locate(draft, from)\n if (found === undefined) return refuse('/model/fields', `No field at \"${from.join('.')}\".`)\n const [moved] = found.siblings.splice(found.index, 1)\n const container = containerAt(draft, to.parent)\n if (container === undefined) {\n return refuse('/model/fields', `No container at \"${to.parent.join('.')}\".`)\n }\n container.splice(clampIndex(to.index, container.length), 0, moved!)\n return undefined\n })\n },\n\n renameField(keyPath, newKey) {\n return attempt((draft) => {\n const found = locate(draft, keyPath)\n if (found === undefined) return refuse('/model/fields', `No field at \"${keyPath.join('.')}\".`)\n const field = found.siblings[found.index]!\n const baseline = baselineByCurrentKey.get(field.key) ?? field.key\n\n field.key = newKey\n if (newKey === baseline) {\n // Back where it started: there is nothing to migrate, and leaving a\n // renamedFrom pointing at the current key is itself invalid.\n delete field.renamedFrom\n } else {\n field.renamedFrom = baseline\n }\n baselineByCurrentKey.set(newKey, baseline)\n return undefined\n })\n },\n\n setFieldProperty(keyPath, property, value) {\n return attempt((draft) => {\n const found = locate(draft, keyPath)\n if (found === undefined) return refuse('/model/fields', `No field at \"${keyPath.join('.')}\".`)\n const field = found.siblings[found.index]! as unknown as Record<string, unknown>\n if (value === undefined) delete field[property]\n else field[property] = copy(value)\n return undefined\n })\n },\n\n addRule(rule) {\n return attempt((draft) => {\n draft.logic = draft.logic ?? { rules: [] }\n draft.logic.rules.push(copy(rule))\n return undefined\n })\n },\n\n updateRule(index, rule) {\n return attempt((draft) => {\n const rules = draft.logic?.rules\n if (rules === undefined || index < 0 || index >= rules.length) {\n return refuse('/logic/rules', `No rule at index ${index}.`)\n }\n rules[index] = copy(rule)\n return undefined\n })\n },\n\n removeRule(index) {\n return attempt((draft) => {\n const rules = draft.logic?.rules\n if (rules === undefined || index < 0 || index >= rules.length) {\n return refuse('/logic/rules', `No rule at index ${index}.`)\n }\n rules.splice(index, 1)\n return undefined\n })\n },\n\n validTargets(what) {\n const movingPath = Array.isArray(what) ? (what as readonly string[]) : undefined\n const probe: FieldDef =\n movingPath === undefined\n ? (what as FieldDef)\n : (locate(present, movingPath)?.siblings[locate(present, movingPath)!.index] as FieldDef)\n if (probe === undefined) return []\n\n const targets: Location[] = []\n for (const parent of containerPaths(present)) {\n // A container cannot be moved into itself or its own descendants.\n if (movingPath !== undefined && isPrefix(movingPath, parent)) continue\n\n // Legality is decided by TRYING the edit against the validator, so\n // these rules can never drift from the ones publish enforces.\n const draft = copy(present)\n if (movingPath !== undefined) {\n const found = locate(draft, movingPath)\n if (found === undefined) continue\n found.siblings.splice(found.index, 1)\n }\n const container = containerAt(draft, parent)\n if (container === undefined) continue\n container.push(movingPath === undefined ? withUniqueKey(copy(probe), draft) : copy(probe))\n\n if (verdictFor(draft).valid) targets.push({ parent, index: container.length - 1 })\n }\n return targets\n },\n }\n}\n\n// ---------------------------------------------------------------- navigation\n\ninterface Located {\n siblings: FieldDef[]\n index: number\n}\n\n/** The child list of the container at `keyPath` — the root list for []. */\nfunction containerAt(document: FormSchema, keyPath: readonly string[]): FieldDef[] | undefined {\n if (keyPath.length === 0) return document.model.fields\n const found = locate(document, keyPath)\n if (found === undefined) return undefined\n const field = found.siblings[found.index]!\n if (!CONTAINER_TYPES.has(field.type)) return undefined\n field.fields = field.fields ?? []\n return field.fields\n}\n\nfunction locate(document: FormSchema, keyPath: readonly string[]): Located | undefined {\n if (keyPath.length === 0) return undefined\n let siblings: FieldDef[] = document.model.fields\n for (let depth = 0; depth < keyPath.length; depth++) {\n const index = siblings.findIndex((field) => field.key === keyPath[depth])\n if (index === -1) return undefined\n if (depth === keyPath.length - 1) return { siblings, index }\n const next = siblings[index]!.fields\n if (next === undefined) return undefined\n siblings = next\n }\n return undefined\n}\n\n/** Every container's key path, root first. */\nfunction containerPaths(document: FormSchema): string[][] {\n const paths: string[][] = [[]]\n const walk = (fields: readonly FieldDef[], prefix: string[]): void => {\n for (const field of fields) {\n if (!CONTAINER_TYPES.has(field.type)) continue\n const here = [...prefix, field.key]\n paths.push(here)\n walk(field.fields ?? [], here)\n }\n }\n walk(document.model.fields, [])\n return paths\n}\n\nfunction isPrefix(prefix: readonly string[], candidate: readonly string[]): boolean {\n if (prefix.length > candidate.length) return false\n return prefix.every((segment, index) => candidate[index] === segment)\n}\n\nfunction clampIndex(index: number, length: number): number {\n if (!Number.isInteger(index) || index < 0) return 0\n return Math.min(index, length)\n}\n\n/** A palette probe must not fail purely because its placeholder key is taken —\n * validTargets answers \"may this SHAPE go here\", not \"is this key free\". */\nfunction withUniqueKey(def: FieldDef, document: FormSchema): FieldDef {\n const taken = new Set<string>()\n const walk = (fields: readonly FieldDef[]): void => {\n for (const field of fields) {\n taken.add(field.key)\n walk(field.fields ?? [])\n }\n }\n walk(document.model.fields)\n\n let candidate = def.key\n let counter = 1\n while (taken.has(candidate)) candidate = `${def.key}_${counter++}`\n return { ...def, key: candidate }\n}\n\n// ------------------------------------------------------------------ baseline\n\nfunction indexBaseline(fields: readonly FieldDef[], into: Map<FieldDef, string>): void {\n for (const field of fields) {\n into.set(field, field.key)\n indexBaseline(field.fields ?? [], into)\n }\n}\n\nfunction seedBaselineByKey(fields: readonly FieldDef[], into: Map<string, string>): void {\n for (const field of fields) {\n // A field opened with a renamedFrom already declared keeps pointing there:\n // that is the key the collected answers actually live under.\n into.set(field.key, field.renamedFrom ?? field.key)\n seedBaselineByKey(field.fields ?? [], into)\n }\n}\n\n// --------------------------------------------------------------------- utils\n\nfunction verdictFor(document: FormSchema): { valid: boolean; errors: SchemaError[] } {\n const result = validateSchema(document)\n return result.valid ? { valid: true, errors: [] } : { valid: false, errors: result.errors }\n}\n\n/** JSON round-trip: a form document is JSON by definition, and this package\n * runs without structuredClone in its lib on purpose. */\nfunction copy<T>(value: T): T {\n return JSON.parse(JSON.stringify(value)) as T\n}\n\nfunction deepFreeze<T>(value: T): T {\n if (value === null || typeof value !== 'object') return value\n for (const nested of Object.values(value as Record<string, unknown>)) deepFreeze(nested)\n return Object.freeze(value)\n}\n"],"mappings":";;AAyEA,MAAM,kCAAkB,IAAI,IAAI;CAAC;CAAS;CAAQ;AAAU,CAAC;AAE7D,SAAgB,qBAAqB,SAAqC;CACxE,MAAM,SAAS,WAAW,KAAK,OAAO,CAAC;CACvC,MAAM,UAAU,WAAW,MAAM;CACjC,IAAI,CAAC,QAAQ,OAIX,MAAM,IAAI,MACR,mDAAmD,QAAQ,OACxD,KAAK,UAAU,GAAG,MAAM,KAAK,GAAG,MAAM,SAAS,CAAC,CAChD,KAAK,IAAI,GACd;;;;;;CAQF,MAAM,+BAAe,IAAI,IAAs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,IAAY;CAC9B,MAAM,QAAQ,WAAsC;EAClD,KAAK,MAAM,SAAS,QAAQ;GAC1B,MAAM,IAAI,MAAM,GAAG;GACnB,KAAK,MAAM,UAAU,CAAC,CAAC;EACzB;CACF;CACA,KAAK,SAAS,MAAM,MAAM;CAE1B,IAAI,YAAY,IAAI;CACpB,IAAI,UAAU;CACd,OAAO,MAAM,IAAI,SAAS,GAAG,YAAY,GAAG,IAAI,IAAI,GAAG;CACvD,OAAO;EAAE,GAAG;EAAK,KAAK;CAAU;AAClC;AAIA,SAAS,cAAc,QAA6B,MAAmC;CACrF,KAAK,MAAM,SAAS,QAAQ;EAC1B,KAAK,IAAI,OAAO,MAAM,GAAG;EACzB,cAAc,MAAM,UAAU,CAAC,GAAG,IAAI;CACxC;AACF;AAEA,SAAS,kBAAkB,QAA6B,MAAiC;CACvF,KAAK,MAAM,SAAS,QAAQ;EAG1B,KAAK,IAAI,MAAM,KAAK,MAAM,eAAe,MAAM,GAAG;EAClD,kBAAkB,MAAM,UAAU,CAAC,GAAG,IAAI;CAC5C;AACF;AAIA,SAAS,WAAW,UAAiE;CACnF,MAAM,SAAS,eAAe,QAAQ;CACtC,OAAO,OAAO,QAAQ;EAAE,OAAO;EAAM,QAAQ,CAAC;CAAE,IAAI;EAAE,OAAO;EAAO,QAAQ,OAAO;CAAO;AAC5F;;;AAIA,SAAS,KAAQ,OAAa;CAC5B,OAAO,KAAK,MAAM,KAAK,UAAU,KAAK,CAAC;AACzC;AAEA,SAAS,WAAc,OAAa;CAClC,IAAI,UAAU,QAAQ,OAAO,UAAU,UAAU,OAAO;CACxD,KAAK,MAAM,UAAU,OAAO,OAAO,KAAgC,GAAG,WAAW,MAAM;CACvF,OAAO,OAAO,OAAO,KAAK;AAC5B"}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@formancy/builder-core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "The headless form-builder document engine: schema editing as commands with undo, selection and valid-target computation.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.mts",
|
|
11
|
+
"default": "./dist/index.mjs"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"LICENSE",
|
|
17
|
+
"NOTICE"
|
|
18
|
+
],
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@formancy/spec": "0.1.0"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@arethetypeswrong/cli": "^0.18.5",
|
|
24
|
+
"fast-check": "^4.10.1",
|
|
25
|
+
"publint": "^0.3.24",
|
|
26
|
+
"tsdown": "^0.23.0",
|
|
27
|
+
"typescript": "~6.0.3",
|
|
28
|
+
"unrun": "^0.3.1",
|
|
29
|
+
"vitest": "^5.0.1"
|
|
30
|
+
},
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public"
|
|
33
|
+
},
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "git+https://github.com/sharkysan/formancy.ai.git",
|
|
37
|
+
"directory": "packages/builder-core"
|
|
38
|
+
},
|
|
39
|
+
"homepage": "https://github.com/sharkysan/formancy.ai",
|
|
40
|
+
"bugs": "https://github.com/sharkysan/formancy.ai/issues",
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "tsdown",
|
|
43
|
+
"test": "vitest run",
|
|
44
|
+
"typecheck": "tsc --noEmit",
|
|
45
|
+
"check:pkg": "publint && attw --pack . --profile esm-only"
|
|
46
|
+
}
|
|
47
|
+
}
|