@texaryn/svelte 0.0.0-stage → 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/CHANGELOG.md +34 -0
- package/LICENSE +190 -0
- package/README.md +128 -2
- package/dist/components/ArrayControl.svelte +210 -0
- package/dist/components/ArrayControl.svelte.d.ts +8 -0
- package/dist/components/ArrayControl.svelte.d.ts.map +1 -0
- package/dist/components/DocumentList.svelte +22 -0
- package/dist/components/DocumentList.svelte.d.ts +9 -0
- package/dist/components/DocumentList.svelte.d.ts.map +1 -0
- package/dist/components/DocumentNode.svelte +68 -0
- package/dist/components/DocumentNode.svelte.d.ts +14 -0
- package/dist/components/DocumentNode.svelte.d.ts.map +1 -0
- package/dist/components/DocumentRoot.svelte +33 -0
- package/dist/components/DocumentRoot.svelte.d.ts +13 -0
- package/dist/components/DocumentRoot.svelte.d.ts.map +1 -0
- package/dist/components/DocumentTable.svelte +35 -0
- package/dist/components/DocumentTable.svelte.d.ts +9 -0
- package/dist/components/DocumentTable.svelte.d.ts.map +1 -0
- package/dist/components/ErrorSummary.svelte +41 -0
- package/dist/components/ErrorSummary.svelte.d.ts +21 -0
- package/dist/components/ErrorSummary.svelte.d.ts.map +1 -0
- package/dist/components/FieldErrors.svelte +14 -0
- package/dist/components/FieldErrors.svelte.d.ts +23 -0
- package/dist/components/FieldErrors.svelte.d.ts.map +1 -0
- package/dist/components/FieldWidget.svelte +109 -0
- package/dist/components/FieldWidget.svelte.d.ts +22 -0
- package/dist/components/FieldWidget.svelte.d.ts.map +1 -0
- package/dist/components/FormRoot.svelte +96 -0
- package/dist/components/FormRoot.svelte.d.ts +17 -0
- package/dist/components/FormRoot.svelte.d.ts.map +1 -0
- package/dist/components/NodeRenderer.svelte +19 -0
- package/dist/components/NodeRenderer.svelte.d.ts +8 -0
- package/dist/components/NodeRenderer.svelte.d.ts.map +1 -0
- package/dist/components/ObjectLayout.svelte +72 -0
- package/dist/components/ObjectLayout.svelte.d.ts +8 -0
- package/dist/components/ObjectLayout.svelte.d.ts.map +1 -0
- package/dist/context.d.ts +13 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +12 -0
- package/dist/field-props.d.ts +20 -0
- package/dist/field-props.d.ts.map +1 -0
- package/dist/field-props.js +31 -0
- package/dist/field.d.ts +34 -0
- package/dist/field.d.ts.map +1 -0
- package/dist/field.js +116 -0
- package/dist/form.d.ts +17 -0
- package/dist/form.d.ts.map +1 -0
- package/dist/form.js +20 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/registry.d.ts +4 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +24 -0
- package/dist/store.d.ts +4 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +7 -0
- package/dist/svelte.d.ts +5 -0
- package/dist/widget.d.ts +10 -0
- package/dist/widget.d.ts.map +1 -0
- package/dist/widget.js +1 -0
- package/package.json +68 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# @texaryn/svelte
|
|
2
|
+
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 3e79b3e: FormRoot now renders the UI tree without creating a native form. Consumers own
|
|
8
|
+
the form element and connect its submit event to the runtime.
|
|
9
|
+
- 3e79b3e: Give every renderer one localized validation message contract and normalize
|
|
10
|
+
adapter parameters so built-in widgets do not display evaluator diagnostics.
|
|
11
|
+
- 3e79b3e: Make the form root error summary opt in, matching the other renderer bindings.
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Updated dependencies [35cb55f]
|
|
16
|
+
- Updated dependencies [3e79b3e]
|
|
17
|
+
- @texaryn/core@0.16.0
|
|
18
|
+
|
|
19
|
+
## 0.2.0
|
|
20
|
+
|
|
21
|
+
### Minor Changes
|
|
22
|
+
|
|
23
|
+
- 2c2786f: Add a standalone version 2 display document runtime, semantic renderer roots, bounded server update sessions, and validated host action arguments.
|
|
24
|
+
- 2c2786f: Add native drag reorder to every array renderer while retaining the existing accessible move controls.
|
|
25
|
+
|
|
26
|
+
### Patch Changes
|
|
27
|
+
|
|
28
|
+
- Updated dependencies [2c2786f]
|
|
29
|
+
- Updated dependencies [2c2786f]
|
|
30
|
+
- @texaryn/core@0.15.0
|
|
31
|
+
|
|
32
|
+
## 0.1.0
|
|
33
|
+
|
|
34
|
+
Initial Svelte 5 renderer release.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding any notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2024-2026 Hamza Hamidi
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,129 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @texaryn/svelte
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Svelte 5 bindings and a default renderer for Texaryn. The package connects
|
|
4
|
+
Svelte stores and components to the shared Texaryn runtime. Schema projection,
|
|
5
|
+
validation, and form commands remain in `@texaryn/core` and the selected schema
|
|
6
|
+
adapter.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
pnpm add @texaryn/core @texaryn/schema-json @texaryn/svelte svelte
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Svelte 5.20 or newer is required.
|
|
15
|
+
|
|
16
|
+
## Use
|
|
17
|
+
|
|
18
|
+
Create the schema adapter before mounting the component tree, then create a
|
|
19
|
+
runtime in a component whose lifetime matches the form.
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
// main.ts
|
|
23
|
+
import { mount } from 'svelte'
|
|
24
|
+
import { createJsonSchemaAdapter } from '@texaryn/schema-json'
|
|
25
|
+
import App from './App.svelte'
|
|
26
|
+
|
|
27
|
+
const adapter = await createJsonSchemaAdapter({
|
|
28
|
+
type: 'object',
|
|
29
|
+
title: 'Profile',
|
|
30
|
+
required: ['name'],
|
|
31
|
+
properties: {
|
|
32
|
+
name: { type: 'string', title: 'Name', minLength: 2 },
|
|
33
|
+
age: { type: 'integer', title: 'Age', minimum: 18 },
|
|
34
|
+
},
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
mount(App, {
|
|
38
|
+
target: document.getElementById('app')!,
|
|
39
|
+
props: { adapter },
|
|
40
|
+
})
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
```svelte
|
|
44
|
+
<!-- App.svelte -->
|
|
45
|
+
<script lang="ts">
|
|
46
|
+
import type { SchemaEvaluationPort } from '@texaryn/core'
|
|
47
|
+
import { createDefaultRegistry, createForm, FormRoot } from '@texaryn/svelte'
|
|
48
|
+
|
|
49
|
+
let { adapter }: { adapter: SchemaEvaluationPort } = $props()
|
|
50
|
+
const form = createForm(adapter, { initialData: { name: '', age: 18 } })
|
|
51
|
+
const data = form.data
|
|
52
|
+
const registry = createDefaultRegistry()
|
|
53
|
+
|
|
54
|
+
function submit(event: SubmitEvent) {
|
|
55
|
+
event.preventDefault()
|
|
56
|
+
form.dispatch({ type: 'Submit' })
|
|
57
|
+
}
|
|
58
|
+
</script>
|
|
59
|
+
|
|
60
|
+
<form novalidate onsubmit={submit}>
|
|
61
|
+
<FormRoot {form} {registry} showErrorSummary>
|
|
62
|
+
<h2>Data</h2>
|
|
63
|
+
<pre>{JSON.stringify($data, null, 2)}</pre>
|
|
64
|
+
</FormRoot>
|
|
65
|
+
<button type="submit">Submit</button>
|
|
66
|
+
</form>
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
`FormRoot` renders the tree only. The application owns the native `<form>` and
|
|
70
|
+
connects its submit event to the runtime, so the tree can also be composed
|
|
71
|
+
inside a larger form.
|
|
72
|
+
|
|
73
|
+
`FormRoot` creates a server rendering safe id prefix with Svelte's component id
|
|
74
|
+
unless `idPrefix` is provided. The prefix must be unique among forms rendered
|
|
75
|
+
by the same component tree. `FormRoot` destroys the runtime when it unmounts by
|
|
76
|
+
default. Set `destroyOnUnmount={false}` when another owner manages the runtime.
|
|
77
|
+
|
|
78
|
+
The default registry renders text, number, checkbox, enum, object, and array
|
|
79
|
+
nodes. It also includes field errors, a live error summary, array add and
|
|
80
|
+
remove controls, and opt in reorder controls driven by `canReorder` UI hints.
|
|
81
|
+
`FormRoot` accepts a complete custom `FormMessages` object, or uses the English
|
|
82
|
+
defaults.
|
|
83
|
+
|
|
84
|
+
## Custom widgets
|
|
85
|
+
|
|
86
|
+
Widgets are Svelte 5 components that accept a `node` prop. Add them to a
|
|
87
|
+
`RendererRegistry<WidgetComponent>` and pass that registry to `FormRoot`.
|
|
88
|
+
Descendants can call `useFormContext()` to read the form, registry, messages,
|
|
89
|
+
and id prefix. The call must happen while the component is being initialized
|
|
90
|
+
below `FormRoot`.
|
|
91
|
+
|
|
92
|
+
```svelte
|
|
93
|
+
<script lang="ts">
|
|
94
|
+
import type { UINode } from '@texaryn/core'
|
|
95
|
+
import { useFormContext } from '@texaryn/svelte'
|
|
96
|
+
|
|
97
|
+
let { node }: { node: UINode } = $props()
|
|
98
|
+
const { form } = useFormContext()
|
|
99
|
+
</script>
|
|
100
|
+
|
|
101
|
+
<div data-node-id={node.id}>{node.annotations.title}</div>
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
`createFieldBinding` adapts a field node and runtime state to Svelte readable
|
|
105
|
+
stores. The default field widget uses it to preserve enum values of different
|
|
106
|
+
types, update validation state, and connect labels and errors through ARIA
|
|
107
|
+
attributes.
|
|
108
|
+
|
|
109
|
+
## Runtime ownership
|
|
110
|
+
|
|
111
|
+
`createForm` returns readable stores backed by the framework-neutral runtime.
|
|
112
|
+
Mount one runtime per form and let `FormRoot` own its teardown, or disable
|
|
113
|
+
`destroyOnUnmount` when an application has an explicit owner. Unmounting
|
|
114
|
+
unsubscribes the Svelte bridge stores and stops runtime validation work.
|
|
115
|
+
|
|
116
|
+
The package depends on `@texaryn/core` and Svelte. It does not depend on
|
|
117
|
+
`@texaryn/react`, Vue, or a second form state library.
|
|
118
|
+
|
|
119
|
+
## Related packages
|
|
120
|
+
|
|
121
|
+
- [`@texaryn/core`](../core/README.md), runtime and renderer contracts
|
|
122
|
+
- [`@texaryn/schema-json`](../schema-json/README.md), JSON Schema adapter
|
|
123
|
+
- [`@texaryn/react`](../react/README.md), React bindings for the same runtime
|
|
124
|
+
|
|
125
|
+
See the [repository README](../../README.md) for the complete architecture.
|
|
126
|
+
|
|
127
|
+
## License
|
|
128
|
+
|
|
129
|
+
Apache-2.0
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { onDestroy, tick } from 'svelte'
|
|
3
|
+
import type { ContainerNode, FormRuntime, StableItemId, UINode } from '@texaryn/core'
|
|
4
|
+
import { useFormContext } from '../context.js'
|
|
5
|
+
import NodeRenderer from './NodeRenderer.svelte'
|
|
6
|
+
|
|
7
|
+
interface Props {
|
|
8
|
+
node: UINode
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
let { node }: Props = $props()
|
|
12
|
+
const context = useFormContext()
|
|
13
|
+
const document = context.form.document
|
|
14
|
+
const messages = context.messages
|
|
15
|
+
const current = $derived(($document.nodes[node.id] ?? node) as ContainerNode)
|
|
16
|
+
const meta = $derived(current.arrayMeta)
|
|
17
|
+
const items = $derived((meta?.itemIds ?? []).map((id, index) => ({
|
|
18
|
+
id,
|
|
19
|
+
nodeId: current.children[index],
|
|
20
|
+
})))
|
|
21
|
+
const title = $derived(current.annotations.title)
|
|
22
|
+
const itemTemplateTitle = $derived(meta?.itemTitle)
|
|
23
|
+
const arrayDragType = 'application/x-texaryn-array-item'
|
|
24
|
+
let root: HTMLDivElement
|
|
25
|
+
let dragSession = $state.raw<{
|
|
26
|
+
runtime: FormRuntime
|
|
27
|
+
identityKey: NonNullable<ContainerNode['arrayMeta']>['identityKey']
|
|
28
|
+
root: HTMLDivElement
|
|
29
|
+
itemId: StableItemId
|
|
30
|
+
} | null>(null)
|
|
31
|
+
const canDrag = $derived(meta?.canReorder === true && !current.readOnly && !current.disabled)
|
|
32
|
+
|
|
33
|
+
function clearDrag(): void {
|
|
34
|
+
root?.removeAttribute('data-array-drag-active')
|
|
35
|
+
root?.querySelectorAll<HTMLElement>('[data-dragging], [data-drop-target]').forEach((row) => {
|
|
36
|
+
row.removeAttribute('data-dragging')
|
|
37
|
+
row.removeAttribute('data-drop-target')
|
|
38
|
+
})
|
|
39
|
+
dragSession = null
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function ownsArrayTarget(event: DragEvent): boolean {
|
|
43
|
+
return event.target instanceof Element && event.target.closest('[data-array-container]') === root
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
$effect(() => {
|
|
47
|
+
const session = dragSession
|
|
48
|
+
if (!session) return
|
|
49
|
+
if (
|
|
50
|
+
session.runtime !== context.form.runtime || session.root !== root ||
|
|
51
|
+
session.identityKey !== meta?.identityKey || !canDrag ||
|
|
52
|
+
!items.some((item) => item.id === session.itemId)
|
|
53
|
+
) clearDrag()
|
|
54
|
+
})
|
|
55
|
+
onDestroy(clearDrag)
|
|
56
|
+
|
|
57
|
+
function add(): void {
|
|
58
|
+
context.form.dispatch({ type: 'InsertItem', containerId: current.id, index: items.length })
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function remove(index: number): void {
|
|
62
|
+
context.form.dispatch({ type: 'RemoveItem', containerId: current.id, index })
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async function move(from: number, to: number, event: MouseEvent): Promise<void> {
|
|
66
|
+
const button = event.currentTarget as HTMLButtonElement
|
|
67
|
+
const wasFocused = globalThis.document.activeElement === button
|
|
68
|
+
const row = button.closest<HTMLElement>('[data-array-row]')
|
|
69
|
+
context.form.dispatch({ type: 'MoveItem', containerId: current.id, from, to })
|
|
70
|
+
|
|
71
|
+
if (!wasFocused) return
|
|
72
|
+
if (to < from && to === 0) {
|
|
73
|
+
await tick()
|
|
74
|
+
row?.querySelector<HTMLButtonElement>(':scope > [data-reorder-direction="down"]')?.focus()
|
|
75
|
+
}
|
|
76
|
+
if (to > from && to === items.length - 1) {
|
|
77
|
+
await tick()
|
|
78
|
+
row?.querySelector<HTMLButtonElement>(':scope > [data-reorder-direction="up"]')?.focus()
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
</script>
|
|
82
|
+
|
|
83
|
+
<div bind:this={root} data-array-container="">
|
|
84
|
+
{#each items as item, index (item.id)}
|
|
85
|
+
{@const child = item.nodeId ? $document.nodes[item.nodeId] : undefined}
|
|
86
|
+
{@const itemTitle = child?.annotations.title}
|
|
87
|
+
<div
|
|
88
|
+
role="presentation"
|
|
89
|
+
data-array-row
|
|
90
|
+
data-array-item-id={item.id}
|
|
91
|
+
ondragover={(event) => {
|
|
92
|
+
if (!Array.from(event.dataTransfer?.types ?? []).includes(arrayDragType)) return
|
|
93
|
+
if (!root || !ownsArrayTarget(event)) {
|
|
94
|
+
event.stopPropagation()
|
|
95
|
+
return
|
|
96
|
+
}
|
|
97
|
+
const session = dragSession
|
|
98
|
+
const ids = meta?.itemIds ?? []
|
|
99
|
+
if (
|
|
100
|
+
!session || session.runtime !== context.form.runtime || session.root !== root ||
|
|
101
|
+
session.identityKey !== meta?.identityKey || !canDrag ||
|
|
102
|
+
!ids.includes(session.itemId) || !ids.includes(item.id)
|
|
103
|
+
) {
|
|
104
|
+
event.stopPropagation()
|
|
105
|
+
return
|
|
106
|
+
}
|
|
107
|
+
event.preventDefault()
|
|
108
|
+
event.stopPropagation()
|
|
109
|
+
if (event.dataTransfer) event.dataTransfer.dropEffect = 'move'
|
|
110
|
+
event.currentTarget.setAttribute('data-drop-target', '')
|
|
111
|
+
}}
|
|
112
|
+
ondragleave={(event) => {
|
|
113
|
+
if (Array.from(event.dataTransfer?.types ?? []).includes(arrayDragType)) {
|
|
114
|
+
event.currentTarget.removeAttribute('data-drop-target')
|
|
115
|
+
}
|
|
116
|
+
}}
|
|
117
|
+
ondrop={(event) => {
|
|
118
|
+
if (!Array.from(event.dataTransfer?.types ?? []).includes(arrayDragType)) return
|
|
119
|
+
event.stopPropagation()
|
|
120
|
+
const session = dragSession
|
|
121
|
+
const ids = meta?.itemIds ?? []
|
|
122
|
+
if (!root || !ownsArrayTarget(event) || !session) {
|
|
123
|
+
clearDrag()
|
|
124
|
+
return
|
|
125
|
+
}
|
|
126
|
+
const sourceIndex = ids.indexOf(session.itemId)
|
|
127
|
+
const targetIndex = ids.indexOf(item.id)
|
|
128
|
+
if (
|
|
129
|
+
session.runtime !== context.form.runtime || session.root !== root ||
|
|
130
|
+
session.identityKey !== meta?.identityKey || !canDrag || sourceIndex < 0 || targetIndex < 0
|
|
131
|
+
) {
|
|
132
|
+
clearDrag()
|
|
133
|
+
return
|
|
134
|
+
}
|
|
135
|
+
event.preventDefault()
|
|
136
|
+
const bounds = event.currentTarget.getBoundingClientRect()
|
|
137
|
+
const after = event.clientY >= bounds.top + bounds.height / 2
|
|
138
|
+
const boundary = targetIndex + (after ? 1 : 0)
|
|
139
|
+
const destination = boundary > sourceIndex ? boundary - 1 : boundary
|
|
140
|
+
clearDrag()
|
|
141
|
+
if (destination !== sourceIndex) context.form.dispatch({
|
|
142
|
+
type: 'MoveItem', containerId: current.id, from: sourceIndex, to: destination,
|
|
143
|
+
})
|
|
144
|
+
}}
|
|
145
|
+
>
|
|
146
|
+
{#if canDrag}
|
|
147
|
+
<span
|
|
148
|
+
aria-hidden="true"
|
|
149
|
+
class="texaryn-array-drag-handle"
|
|
150
|
+
draggable={true}
|
|
151
|
+
tabindex="-1"
|
|
152
|
+
ondragstart={(event) => {
|
|
153
|
+
const identityKey = meta?.identityKey
|
|
154
|
+
if (!canDrag || !root || identityKey === undefined || !meta?.itemIds.includes(item.id)) {
|
|
155
|
+
event.preventDefault()
|
|
156
|
+
return
|
|
157
|
+
}
|
|
158
|
+
event.stopPropagation()
|
|
159
|
+
event.dataTransfer?.setData(arrayDragType, item.id)
|
|
160
|
+
if (event.dataTransfer) event.dataTransfer.effectAllowed = 'move'
|
|
161
|
+
dragSession = { runtime: context.form.runtime, identityKey, root, itemId: item.id }
|
|
162
|
+
root.setAttribute('data-array-drag-active', '')
|
|
163
|
+
event.currentTarget.closest<HTMLElement>('[data-array-row]')?.setAttribute('data-dragging', '')
|
|
164
|
+
}}
|
|
165
|
+
ondragend={(event) => {
|
|
166
|
+
event.dataTransfer?.clearData(arrayDragType)
|
|
167
|
+
clearDrag()
|
|
168
|
+
}}
|
|
169
|
+
>⠿</span>
|
|
170
|
+
{/if}
|
|
171
|
+
{#if child}<NodeRenderer node={child} />{/if}
|
|
172
|
+
|
|
173
|
+
{#if meta?.canReorder && index > 0}
|
|
174
|
+
{@const message = $messages.moveItemUp({ position: index + 1, itemTitle, containerTitle: title })}
|
|
175
|
+
<button
|
|
176
|
+
type="button"
|
|
177
|
+
aria-label={message.accessibleName}
|
|
178
|
+
data-reorder-direction="up"
|
|
179
|
+
onclick={(event) => void move(index, index - 1, event)}
|
|
180
|
+
>
|
|
181
|
+
{message.label}
|
|
182
|
+
</button>
|
|
183
|
+
{/if}
|
|
184
|
+
|
|
185
|
+
{#if meta?.canReorder && index < items.length - 1}
|
|
186
|
+
{@const message = $messages.moveItemDown({ position: index + 1, itemTitle, containerTitle: title })}
|
|
187
|
+
<button
|
|
188
|
+
type="button"
|
|
189
|
+
aria-label={message.accessibleName}
|
|
190
|
+
data-reorder-direction="down"
|
|
191
|
+
onclick={(event) => void move(index, index + 1, event)}
|
|
192
|
+
>
|
|
193
|
+
{message.label}
|
|
194
|
+
</button>
|
|
195
|
+
{/if}
|
|
196
|
+
|
|
197
|
+
{#if meta?.canRemove}
|
|
198
|
+
{@const message = $messages.removeItem({ position: index + 1, itemTitle, containerTitle: title })}
|
|
199
|
+
<button type="button" aria-label={message.accessibleName} onclick={() => remove(index)}>
|
|
200
|
+
{message.label}
|
|
201
|
+
</button>
|
|
202
|
+
{/if}
|
|
203
|
+
</div>
|
|
204
|
+
{/each}
|
|
205
|
+
|
|
206
|
+
{#if meta?.canAdd}
|
|
207
|
+
{@const message = $messages.addItem({ itemTemplateTitle, containerTitle: title })}
|
|
208
|
+
<button type="button" aria-label={message.accessibleName} onclick={add}>{message.label}</button>
|
|
209
|
+
{/if}
|
|
210
|
+
</div>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { UINode } from '@texaryn/core';
|
|
2
|
+
interface Props {
|
|
3
|
+
node: UINode;
|
|
4
|
+
}
|
|
5
|
+
declare const ArrayControl: import("svelte").Component<Props, {}, "">;
|
|
6
|
+
type ArrayControl = ReturnType<typeof ArrayControl>;
|
|
7
|
+
export default ArrayControl;
|
|
8
|
+
//# sourceMappingURL=ArrayControl.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ArrayControl.svelte.d.ts","sourceRoot":"","sources":["../../src/lib/components/ArrayControl.svelte.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAA4C,MAAM,EAAE,MAAM,eAAe,CAAA;AAKnF,UAAU,KAAK;IACb,IAAI,EAAE,MAAM,CAAA;CACb;AA2LH,QAAA,MAAM,YAAY,2CAAwC,CAAC;AAC3D,KAAK,YAAY,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC;AACpD,eAAe,YAAY,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { DocumentCollectionRow, DocumentRuntime, ListNode } from '@texaryn/core'
|
|
3
|
+
|
|
4
|
+
let { node, runtime }: { node: ListNode; runtime: DocumentRuntime } = $props()
|
|
5
|
+
let rows = $state<readonly DocumentCollectionRow[]>([])
|
|
6
|
+
|
|
7
|
+
$effect(() => {
|
|
8
|
+
const store = runtime.getCollection(node.id)
|
|
9
|
+
if (!store) {
|
|
10
|
+
rows = []
|
|
11
|
+
return
|
|
12
|
+
}
|
|
13
|
+
rows = store.getSnapshot()
|
|
14
|
+
return store.subscribe(() => { rows = store.getSnapshot() })
|
|
15
|
+
})
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<ul>
|
|
19
|
+
{#each rows as row (row.id)}
|
|
20
|
+
<li>{row.value === null ? '' : String(row.value)}</li>
|
|
21
|
+
{/each}
|
|
22
|
+
</ul>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { DocumentRuntime, ListNode } from '@texaryn/core';
|
|
2
|
+
type $$ComponentProps = {
|
|
3
|
+
node: ListNode;
|
|
4
|
+
runtime: DocumentRuntime;
|
|
5
|
+
};
|
|
6
|
+
declare const DocumentList: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
7
|
+
type DocumentList = ReturnType<typeof DocumentList>;
|
|
8
|
+
export default DocumentList;
|
|
9
|
+
//# sourceMappingURL=DocumentList.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DocumentList.svelte.d.ts","sourceRoot":"","sources":["../../src/lib/components/DocumentList.svelte.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAyB,eAAe,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAErF,KAAK,gBAAgB,GAAI;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,OAAO,EAAE,eAAe,CAAA;CAAE,CAAC;AA0BvE,QAAA,MAAM,YAAY,sDAAwC,CAAC;AAC3D,KAAK,YAAY,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC;AACpD,eAAe,YAAY,CAAC"}
|