@orieljs/live 0.1.0-alpha.10
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 +16 -0
- package/README.md +265 -0
- package/TRADEMARKS.md +33 -0
- package/dist/index.d.ts +519 -0
- package/dist/index.js +1991 -0
- package/dist/index.js.map +1 -0
- package/package.json +42 -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
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
Oriel
|
|
2
|
+
Copyright 2026 meeeet-dev and Oriel contributors
|
|
3
|
+
|
|
4
|
+
This product includes software developed by the Oriel project
|
|
5
|
+
(https://orieljs.vercel.app, https://github.com/orieljs).
|
|
6
|
+
|
|
7
|
+
Oriel is licensed under the Apache License, Version 2.0 (see LICENSE).
|
|
8
|
+
The Oriel name and logo are not covered by that license; see TRADEMARKS.md
|
|
9
|
+
(https://github.com/orieljs/framework/blob/main/TRADEMARKS.md).
|
|
10
|
+
|
|
11
|
+
@orieljs/support (and @orieljs/framework, which bundles it) includes transliteration data from
|
|
12
|
+
voku/portable-ascii (https://github.com/voku/portable-ascii), Copyright (C) 2019 Lars Moelleken, MIT License.
|
|
13
|
+
|
|
14
|
+
@orieljs/notifications (and @orieljs/framework, which bundles it) includes the HTML and CSS of
|
|
15
|
+
Laravel's default notification mail (laravel/framework, https://github.com/laravel/framework),
|
|
16
|
+
Copyright (c) Taylor Otwell, MIT License.
|
package/README.md
ADDED
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
# @orieljs/live
|
|
2
|
+
|
|
3
|
+
Server-side Live components for Oriel: Livewire-style components written in TSX, with signed snapshots, actions, events and `Live.test()`. Live is part of `@orieljs/framework`, which every Oriel app already installs, and is re-exported from it. Its semantics follow Livewire 3. In an app, import it from `@orieljs/framework` only: `@orieljs/live` is also published on its own, but a separate copy doesn't share the framework's per-request state.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install @orieljs/framework
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```tsx title="app/Live/Counter.tsx"
|
|
10
|
+
import { Component } from '@orieljs/framework'
|
|
11
|
+
|
|
12
|
+
export default class Counter extends Component {
|
|
13
|
+
count = 0
|
|
14
|
+
|
|
15
|
+
increment() {
|
|
16
|
+
this.count++
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
render() {
|
|
20
|
+
return <button o:click="increment">{this.count}</button>
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
```ts title="routes/web.ts"
|
|
26
|
+
// @filename: app/Live/Counter.tsx
|
|
27
|
+
import { Component } from '@orieljs/framework'
|
|
28
|
+
export default class Counter extends Component { render() { return <p /> } }
|
|
29
|
+
// ---cut---
|
|
30
|
+
import { Route } from '@orieljs/framework'
|
|
31
|
+
import Counter from '../app/Live/Counter'
|
|
32
|
+
|
|
33
|
+
Route.get('/counter', Counter)
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Embed a component in any view with `<Live component={Counter} />`. In the browser, components are driven by `@orieljs/live-client`. Public fields are a component's state and its public methods are actions. `mount()` and `render()` may be async (`const user = await request().user<User>()`), and `await this.validate(rules)` returns the validated data, typed from the rules.
|
|
37
|
+
|
|
38
|
+
## Typed actions
|
|
39
|
+
|
|
40
|
+
`this.$action(method, ...arguments)` writes an action for an `o:` directive, typed against the method:
|
|
41
|
+
|
|
42
|
+
```tsx title="app/Live/Drafts.tsx"
|
|
43
|
+
import { Component } from '@orieljs/framework'
|
|
44
|
+
import { Post } from '../Models/Post'
|
|
45
|
+
|
|
46
|
+
export default class Drafts extends Component {
|
|
47
|
+
async publish(id: number) {
|
|
48
|
+
const post = await Post.findOrFail(id)
|
|
49
|
+
post.published_at = new Date()
|
|
50
|
+
await post.save()
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async render() {
|
|
54
|
+
const drafts = await Post.whereNull('published_at').get()
|
|
55
|
+
return (
|
|
56
|
+
<ul>
|
|
57
|
+
{drafts.map((post) => (
|
|
58
|
+
<li>
|
|
59
|
+
{post.title}
|
|
60
|
+
<button type="button" o:click={this.$action(this.publish, post.id)}>Publish</button>
|
|
61
|
+
</li>
|
|
62
|
+
))}
|
|
63
|
+
</ul>
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
For post 5 this renders `o:click="publish(5)"`, and since `publish(id: number)` takes a number,
|
|
70
|
+
`this.$action(this.publish, String(post.id))` is a type error. The arguments are written as JSON, so pass ids and
|
|
71
|
+
plain values (strings, numbers, booleans, `null`, arrays and plain objects): a model arrives as its attributes and a
|
|
72
|
+
date as its ISO string, so pass `post.id`, not `post`. The action contains double quotes, so use it as a TSX attribute
|
|
73
|
+
value, which escapes them, not inside an HTML string you write by hand. Rendering throws when the method isn't one of
|
|
74
|
+
the component's actions (a hook, or a `#private` or `@Locked` method). The types check what your pages send; a crafted
|
|
75
|
+
request can still send anything, so an action checks what it is given, as a controller does.
|
|
76
|
+
|
|
77
|
+
## Confirming an action
|
|
78
|
+
|
|
79
|
+
`o:confirm` asks before an action runs, as Livewire's `wire:confirm`:
|
|
80
|
+
|
|
81
|
+
```tsx
|
|
82
|
+
declare const tag: { id: number }
|
|
83
|
+
// ---cut---
|
|
84
|
+
<button type="button" class="btn btn-danger" o:click={`delete(${tag.id})`} o:confirm="Delete this tag?">
|
|
85
|
+
Delete
|
|
86
|
+
</button>
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
The browser's confirm dialog shows the message (an empty `o:confirm` asks "Are you sure?", and `\n` is a line break),
|
|
90
|
+
and the action runs only when it is accepted. `o:confirm-prompt="Type DELETE to confirm|DELETE"` (`o:confirm.prompt`
|
|
91
|
+
in plain HTML) asks with a prompt instead, and runs the action only when the answer is exactly the text after the `|`.
|
|
92
|
+
It works on any element with an `o:` action: `o:click`, `o:submit` on a form, `o:keydown-enter`, and the others. A
|
|
93
|
+
dismissed dialog stops the event, so the actions of the elements around it don't run either. With `-once`, a dismissed
|
|
94
|
+
dialog doesn't use the action up. `o:confirm` guards the actions of the element it sits on: on a form, put it on the
|
|
95
|
+
`<form>` with the `o:submit`. A button inside a form with its own `o:click` needs `type="button"` or `-prevent`
|
|
96
|
+
(`o:click-prevent`), or the browser still submits the form when the dialog is dismissed.
|
|
97
|
+
|
|
98
|
+
## Pagination
|
|
99
|
+
|
|
100
|
+
```tsx title="app/Live/Posts.tsx"
|
|
101
|
+
import { Component, Pagination, WithPagination } from '@orieljs/framework'
|
|
102
|
+
import { Post } from '../Models/Post'
|
|
103
|
+
|
|
104
|
+
export default class Posts extends WithPagination(Component) {
|
|
105
|
+
search = ''
|
|
106
|
+
|
|
107
|
+
async updatedSearch() {
|
|
108
|
+
await this.resetPage()
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
async render() {
|
|
112
|
+
const posts = await Post.whereLike('title', `%${this.search}%`).latest().paginate(10)
|
|
113
|
+
return (
|
|
114
|
+
<div>
|
|
115
|
+
<input o:model-live="search" aria-label="Search" />
|
|
116
|
+
{posts.items().map((post) => <p>{post.title}</p>)}
|
|
117
|
+
<Pagination paginator={posts} class="flex gap-2" />
|
|
118
|
+
</div>
|
|
119
|
+
)
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
`paginate()` in the component (in `render()`, in `mount()`, in actions and the update hooks, or in a `@Computed`
|
|
125
|
+
getter any of them reads) shows the component's `page`, and its links are built on the page's URL. The actions
|
|
126
|
+
`nextPage`, `previousPage`, `gotoPage(n)`, `setPage(n)` and `resetPage` move it (they are async, so await them in your
|
|
127
|
+
own methods); `<Pagination>` renders them as buttons with the kits' `btn` classes. The page starts at 1 and isn't kept
|
|
128
|
+
in the address bar.
|
|
129
|
+
|
|
130
|
+
## File uploads
|
|
131
|
+
|
|
132
|
+
```tsx title="app/Live/ProfilePhoto.tsx"
|
|
133
|
+
import { Component, TemporaryUploadedFile, WithFileUploads } from '@orieljs/framework'
|
|
134
|
+
|
|
135
|
+
export default class ProfilePhoto extends WithFileUploads(Component) {
|
|
136
|
+
photo: TemporaryUploadedFile | null = null
|
|
137
|
+
|
|
138
|
+
async save() {
|
|
139
|
+
const { photo } = await this.validate({ photo: 'required|image|max:1024' })
|
|
140
|
+
await photo.store('photos')
|
|
141
|
+
this.reset('photo')
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
render() {
|
|
145
|
+
return (
|
|
146
|
+
<form o:submit="save">
|
|
147
|
+
<input type="file" o:model="photo" />
|
|
148
|
+
{this.photo?.isPreviewable() ? <img src={this.photo.temporaryUrl()} alt="Preview" /> : null}
|
|
149
|
+
<button type="submit">Save</button>
|
|
150
|
+
</form>
|
|
151
|
+
)
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
In a `WithFileUploads` component, `o:model` on a file input uploads the picked file at once, to a temporary
|
|
157
|
+
directory, and sets the property to a `TemporaryUploadedFile` (an array of them with `multiple`). Validate it with the
|
|
158
|
+
file rules, preview it with `temporaryUrl()` (a signed link, for images, audio and video), and `store()` it. In tests,
|
|
159
|
+
`Live.test()`'s `set('photo', file)` uploads a file the same way. Every upload must also pass
|
|
160
|
+
`live.temporary_file_upload.rules`, which allow 12 MB (`max:12288`), but a request body larger than
|
|
161
|
+
`http.max_body_size` (8 MB, for every request) gets a 413: raise it in `config/http.ts` to accept files up to the
|
|
162
|
+
rule's size.
|
|
163
|
+
|
|
164
|
+
## Lazy components
|
|
165
|
+
|
|
166
|
+
```tsx title="app/Live/PostCount.tsx"
|
|
167
|
+
import { Component } from '@orieljs/framework'
|
|
168
|
+
import { Post } from '../Models/Post'
|
|
169
|
+
|
|
170
|
+
export default class PostCount extends Component {
|
|
171
|
+
static override lazy = true
|
|
172
|
+
count = 0
|
|
173
|
+
|
|
174
|
+
async mount() {
|
|
175
|
+
this.count = await Post.count()
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
placeholder() {
|
|
179
|
+
return <p>Counting posts…</p>
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
render() {
|
|
183
|
+
return <p>{this.count} posts</p>
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
With `static override lazy = true`, each `<Live component={PostCount} />` (and the full page) renders the
|
|
189
|
+
placeholder first and mounts the component once it scrolls into view. `lazy` on one embed makes that embed lazy,
|
|
190
|
+
`lazy="on-load"` mounts it as soon as the page loads, and `lazy={false}` turns `static lazy` off. Without
|
|
191
|
+
`placeholder()`, the placeholder is the `live.lazy_placeholder` view, else an empty `<div>`; it needs the same root
|
|
192
|
+
element as `render()`.
|
|
193
|
+
|
|
194
|
+
## Navigating
|
|
195
|
+
|
|
196
|
+
`<a href="/posts" o:navigate>` shows the next page without a full reload: Live fetches it (from `mousedown`, or on
|
|
197
|
+
hover with `o:navigate-hover`), merges its `<head>`, swaps the `<body>` and starts the new page's components.
|
|
198
|
+
`this.redirect(url, { navigate: true })` does the same from an action. The new page's scripts run as on a full load,
|
|
199
|
+
except a `<head>` script the page already has, and a `<body>` script marked `data-navigate-once` that an earlier page
|
|
200
|
+
already ran.
|
|
201
|
+
|
|
202
|
+
## Middleware on updates
|
|
203
|
+
|
|
204
|
+
Each update re-runs the `auth`, `verified`, `guest` and `can` middleware of the route that rendered the page
|
|
205
|
+
(Livewire's persistent middleware), with that route's parameters bound again, so `can:update,post` sees the post. A
|
|
206
|
+
signed-out tab gets a 401 and a user who lost the ability a 403, before the component's actions run. On a page behind
|
|
207
|
+
one of these middleware, a model deleted since the page rendered gets a 404 too; a page with none binds nothing on
|
|
208
|
+
updates. The list is `live.persistent_middleware`, which a `config/live.ts` of your own can set.
|
|
209
|
+
|
|
210
|
+
## Flash data in updates
|
|
211
|
+
|
|
212
|
+
A status an action flashes (`session().flash('status', 'Saved.')`) shows in that update's response only, unless the
|
|
213
|
+
action redirects or navigates: then it is there on the next page. Component state is unaffected.
|
|
214
|
+
|
|
215
|
+
## Status messages announced again
|
|
216
|
+
|
|
217
|
+
Screen readers announce a status region (`role="status"`) when its text changes. When an action brings the same
|
|
218
|
+
message again ("Saved" after a second save), the page doesn't change and nothing is announced. Add `o:announce` to the
|
|
219
|
+
region and Live takes the message out and puts it back a moment later, so it is announced again:
|
|
220
|
+
|
|
221
|
+
```tsx title="app/Live/Settings.tsx"
|
|
222
|
+
import { Component } from '@orieljs/framework'
|
|
223
|
+
|
|
224
|
+
export default class Settings extends Component {
|
|
225
|
+
name = ''
|
|
226
|
+
#saved = false
|
|
227
|
+
|
|
228
|
+
save() {
|
|
229
|
+
this.#saved = true
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
render() {
|
|
233
|
+
return (
|
|
234
|
+
<form o:submit="save">
|
|
235
|
+
<input o:model="name" aria-label="Name" />
|
|
236
|
+
<button type="submit">Save</button>
|
|
237
|
+
<p role="status" o:announce>
|
|
238
|
+
{this.#saved ? 'Saved' : ''}
|
|
239
|
+
</p>
|
|
240
|
+
</form>
|
|
241
|
+
)
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
Only actions do this, and an `o:poll` that calls a method counts as one: an update that only syncs `o:model` values,
|
|
247
|
+
refreshes or delivers an event leaves the region alone. Keep a status for one response (a `#private` field, or a
|
|
248
|
+
flashed `status`), so that any other update clears it; a status kept in a public property is announced again by every
|
|
249
|
+
action until it changes, which in a polled component is every tick. Keep an `o:announce` region to text: its children
|
|
250
|
+
are taken out for 100 ms, so a button or input inside it would lose focus.
|
|
251
|
+
|
|
252
|
+
## Known limitations
|
|
253
|
+
|
|
254
|
+
- A DOM event whose name contains `-` can't be an `o:<event>` action, because `-` (and `.`) separate the modifiers (for example `o:model-live`).
|
|
255
|
+
- `temporaryUrl()` previews don't answer range requests, which Safari needs to play a `<video>`.
|
|
256
|
+
|
|
257
|
+
Documentation: https://orieljs.vercel.app/docs/live
|
|
258
|
+
|
|
259
|
+
Status: early alpha. APIs will change.
|
|
260
|
+
|
|
261
|
+
## License
|
|
262
|
+
|
|
263
|
+
Oriel is open-source software licensed under the Apache License 2.0 (Apache-2.0; see `LICENSE` and `NOTICE`). The Oriel name and logo are trademarks; see `TRADEMARKS.md`.
|
|
264
|
+
|
|
265
|
+
Website: https://orieljs.vercel.app
|
package/TRADEMARKS.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Oriel trademark policy
|
|
2
|
+
|
|
3
|
+
The Oriel code is open source under the Apache License 2.0. The **Oriel name and logo** are not: the license covers
|
|
4
|
+
the code only (section 6 of the license says so), and the name and logo stay with the project. This page explains
|
|
5
|
+
what you can and can't do with them. The goal is simple: people should always be able to tell what is the real Oriel
|
|
6
|
+
and what isn't.
|
|
7
|
+
|
|
8
|
+
## You can, without asking
|
|
9
|
+
|
|
10
|
+
- Use, change, ship and sell the code, as the license allows.
|
|
11
|
+
- Say that your app or package is "built with Oriel", "for Oriel" or "compatible with Oriel".
|
|
12
|
+
- Name a package `oriel-<something>` or `<something>-for-oriel` when it works with Oriel, as long as it is clear that
|
|
13
|
+
it is not official (for example, don't publish it under the `@orieljs` npm scope).
|
|
14
|
+
- Use the name and logo to write about Oriel, teach it, or link to it, in articles, talks, videos and courses.
|
|
15
|
+
- Use the unmodified logo to point to the project, as it is (no recolouring, cropping or
|
|
16
|
+
distortion).
|
|
17
|
+
|
|
18
|
+
## You can't, without written permission
|
|
19
|
+
|
|
20
|
+
- Call a fork, a modified copy or a competing product "Oriel", or anything likely to be confused with it.
|
|
21
|
+
- Use the name or logo as the name, logo or domain of your own product, company or service.
|
|
22
|
+
- Suggest that the Oriel project made, endorses or supports your work when it doesn't.
|
|
23
|
+
- Sell merchandise with the name or logo.
|
|
24
|
+
|
|
25
|
+
## Forks
|
|
26
|
+
|
|
27
|
+
Forks are welcome. Please give yours a different name and logo, keep the `LICENSE` and `NOTICE` files, and say that
|
|
28
|
+
it is based on Oriel.
|
|
29
|
+
|
|
30
|
+
## Questions
|
|
31
|
+
|
|
32
|
+
Open an issue at https://github.com/orieljs/framework or email meeeet.dev@gmail.com. If you're unsure whether a use
|
|
33
|
+
is fine, ask; the answer is usually yes.
|