@orieljs/view 0.1.0-alpha.1
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 +9 -0
- package/dist/chunk-KIU7OKDI.js +25 -0
- package/dist/chunk-KIU7OKDI.js.map +1 -0
- package/dist/index.d.ts +208 -0
- package/dist/index.js +481 -0
- package/dist/index.js.map +1 -0
- package/dist/jsx-runtime.d.ts +63 -0
- package/dist/jsx-runtime.js +11 -0
- package/dist/jsx-runtime.js.map +1 -0
- package/package.json +43 -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,9 @@
|
|
|
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).
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Element.ts
|
|
2
|
+
var ELEMENT = /* @__PURE__ */ Symbol.for("oriel:view.element");
|
|
3
|
+
var Fragment = /* @__PURE__ */ Symbol.for("oriel:view.fragment");
|
|
4
|
+
function createElement(type, props, key) {
|
|
5
|
+
return { [ELEMENT]: true, type, props: props ?? {}, key };
|
|
6
|
+
}
|
|
7
|
+
function isElement(value) {
|
|
8
|
+
return typeof value === "object" && value !== null && value[ELEMENT] === true;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// jsx-runtime.ts
|
|
12
|
+
function jsx(type, props, key) {
|
|
13
|
+
return createElement(type, props, key);
|
|
14
|
+
}
|
|
15
|
+
var jsxs = jsx;
|
|
16
|
+
|
|
17
|
+
export {
|
|
18
|
+
ELEMENT,
|
|
19
|
+
Fragment,
|
|
20
|
+
createElement,
|
|
21
|
+
isElement,
|
|
22
|
+
jsx,
|
|
23
|
+
jsxs
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=chunk-KIU7OKDI.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../Element.ts","../jsx-runtime.ts"],"sourcesContent":["import type { Htmlable } from '@orieljs/contracts'\n\n/** Marks the objects jsx() returns (Symbol.for, so two copies of the package agree). */\nexport const ELEMENT: unique symbol = Symbol.for('oriel:view.element')\n\nexport type Props = Record<string, unknown>\n\n/** Anything that can appear as a child: text is escaped, Htmlable is emitted as-is, promises are awaited. */\nexport type Renderable =\n | OrielElement\n | string\n | number\n | bigint\n | boolean\n | null\n | undefined\n | Htmlable\n | Promise<Renderable>\n | Iterable<Renderable>\n\n/** A function component. It may be async: the renderer awaits it. */\nexport type Component<P = Props> = (props: P) => Renderable | Promise<Renderable>\n\n/**\n * `<>…</>` and `<Fragment>`: renders its children only. A symbol at runtime; typed as a component so that\n * `<Fragment>` type-checks as a JSX tag.\n */\nexport const Fragment = Symbol.for('oriel:view.fragment') as unknown as (props: { children?: Renderable }) => Renderable\n\nexport type ElementType = string | Component<never>\n\n/** What `<div />` evaluates to: an inert description, rendered later by renderToString()/renderToStream(). */\nexport interface OrielElement {\n readonly [ELEMENT]: true\n readonly type: ElementType\n readonly props: Props\n readonly key: string | number | undefined\n}\n\nexport function createElement(type: ElementType, props: Props | null | undefined, key?: string | number): OrielElement {\n return { [ELEMENT]: true, type, props: props ?? {}, key }\n}\n\nexport function isElement(value: unknown): value is OrielElement {\n return typeof value === 'object' && value !== null && (value as Record<symbol, unknown>)[ELEMENT] === true\n}\n","/**\n * The automatic JSX runtime (`jsxImportSource: \"@orieljs/view\"`). jsx() only describes elements; rendering\n * (escaping, async components) happens in renderToString()/renderToStream().\n */\nimport type { ClassValue, StyleObject } from './attributes'\nimport { createElement, Fragment, type Component, type ElementType, type OrielElement, type Props, type Renderable } from './Element'\n\nexport { Fragment }\n\nexport function jsx(type: ElementType, props: Props | null, key?: string | number): OrielElement {\n return createElement(type, props, key)\n}\n\n/** Same as jsx(); the compiler uses it when there are several static children. */\nexport const jsxs = jsx\n\n/** Attributes every intrinsic element accepts. Unknown attributes (hx-*, x-*, o:click, …) are allowed. */\nexport interface HtmlAttributes {\n children?: Renderable\n class?: ClassValue\n className?: ClassValue\n style?: string | StyleObject\n dangerouslySetInnerHTML?: { __html: string }\n [attribute: string]: unknown\n}\n\nexport declare namespace JSX {\n type Element = OrielElement\n /** Lets components be async: `async function Posts() { … }` is a valid element type. */\n type ElementType = string | Component<never>\n interface ElementChildrenAttribute {\n children: unknown\n }\n interface IntrinsicAttributes {\n key?: string | number\n }\n interface IntrinsicElements {\n [element: string]: HtmlAttributes\n }\n}\n"],"mappings":";AAGO,IAAM,UAAyB,uBAAO,IAAI,oBAAoB;AAwB9D,IAAM,WAAW,uBAAO,IAAI,qBAAqB;AAYjD,SAAS,cAAc,MAAmB,OAAiC,KAAqC;AACrH,SAAO,EAAE,CAAC,OAAO,GAAG,MAAM,MAAM,OAAO,SAAS,CAAC,GAAG,IAAI;AAC1D;AAEO,SAAS,UAAU,OAAuC;AAC/D,SAAO,OAAO,UAAU,YAAY,UAAU,QAAS,MAAkC,OAAO,MAAM;AACxG;;;ACpCO,SAAS,IAAI,MAAmB,OAAqB,KAAqC;AAC/F,SAAO,cAAc,MAAM,OAAO,GAAG;AACvC;AAGO,IAAM,OAAO;","names":[]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { Htmlable, OrielError, ErrorKind, View as View$1, ViewFactory } from '@orieljs/contracts';
|
|
2
|
+
import * as _orieljs_support from '@orieljs/support';
|
|
3
|
+
import { ServiceProvider } from '@orieljs/support';
|
|
4
|
+
|
|
5
|
+
/** Marks the objects jsx() returns (Symbol.for, so two copies of the package agree). */
|
|
6
|
+
declare const ELEMENT: unique symbol;
|
|
7
|
+
type Props = Record<string, unknown>;
|
|
8
|
+
/** Anything that can appear as a child: text is escaped, Htmlable is emitted as-is, promises are awaited. */
|
|
9
|
+
type Renderable = OrielElement | string | number | bigint | boolean | null | undefined | Htmlable | Promise<Renderable> | Iterable<Renderable>;
|
|
10
|
+
/** A function component. It may be async: the renderer awaits it. */
|
|
11
|
+
type Component<P = Props> = (props: P) => Renderable | Promise<Renderable>;
|
|
12
|
+
/**
|
|
13
|
+
* `<>…</>` and `<Fragment>`: renders its children only. A symbol at runtime; typed as a component so that
|
|
14
|
+
* `<Fragment>` type-checks as a JSX tag.
|
|
15
|
+
*/
|
|
16
|
+
declare const Fragment: (props: {
|
|
17
|
+
children?: Renderable;
|
|
18
|
+
}) => Renderable;
|
|
19
|
+
type ElementType = string | Component<never>;
|
|
20
|
+
/** What `<div />` evaluates to: an inert description, rendered later by renderToString()/renderToStream(). */
|
|
21
|
+
interface OrielElement {
|
|
22
|
+
readonly [ELEMENT]: true;
|
|
23
|
+
readonly type: ElementType;
|
|
24
|
+
readonly props: Props;
|
|
25
|
+
readonly key: string | number | undefined;
|
|
26
|
+
}
|
|
27
|
+
declare function createElement(type: ElementType, props: Props | null | undefined, key?: string | number): OrielElement;
|
|
28
|
+
declare function isElement(value: unknown): value is OrielElement;
|
|
29
|
+
|
|
30
|
+
/** Markup that must not be escaped again (Laravel's Illuminate\Support\HtmlString). */
|
|
31
|
+
declare class HtmlString implements Htmlable {
|
|
32
|
+
private readonly html;
|
|
33
|
+
constructor(html?: string);
|
|
34
|
+
toHtml(): string;
|
|
35
|
+
toString(): string;
|
|
36
|
+
isEmpty(): boolean;
|
|
37
|
+
}
|
|
38
|
+
/** Marks trusted markup so the renderer emits it unescaped: {raw(markdownHtml)}. Never pass user input. */
|
|
39
|
+
declare function raw(html: string): HtmlString;
|
|
40
|
+
declare function isHtmlable(value: unknown): value is Htmlable;
|
|
41
|
+
/** Laravel's e(): htmlspecialchars(ENT_QUOTES, double-encode). Htmlable values pass through; null is ''. */
|
|
42
|
+
declare function e(value: unknown): string;
|
|
43
|
+
|
|
44
|
+
type ClassValue = string | number | null | undefined | false | ClassValue[] | Record<string, unknown>;
|
|
45
|
+
type StyleObject = Record<string, string | number | null | undefined | false>;
|
|
46
|
+
/** `class` accepts strings, arrays and `{ name: condition }` objects, like Blade's @class. */
|
|
47
|
+
declare function classNames(value: ClassValue): string;
|
|
48
|
+
/** `{ marginTop: 4, '--gap': '1rem' }` → `margin-top:4px;--gap:1rem`. */
|
|
49
|
+
declare function styleString(style: StyleObject): string;
|
|
50
|
+
|
|
51
|
+
/** Renders JSX (or any Renderable) to an HTML string. Async components and promises are awaited in order. */
|
|
52
|
+
declare function renderToString(node: Renderable): Promise<string>;
|
|
53
|
+
/** Renders to a UTF-8 byte stream, sending everything rendered so far each time rendering waits on a promise. */
|
|
54
|
+
declare function renderToStream(node: Renderable): ReadableStream<Uint8Array>;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The automatic JSX runtime (`jsxImportSource: "@orieljs/view"`). jsx() only describes elements; rendering
|
|
58
|
+
* (escaping, async components) happens in renderToString()/renderToStream().
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
declare function jsx(type: ElementType, props: Props | null, key?: string | number): OrielElement;
|
|
62
|
+
/** Same as jsx(); the compiler uses it when there are several static children. */
|
|
63
|
+
declare const jsxs: typeof jsx;
|
|
64
|
+
/** Attributes every intrinsic element accepts. Unknown attributes (hx-*, x-*, o:click, …) are allowed. */
|
|
65
|
+
interface HtmlAttributes {
|
|
66
|
+
children?: Renderable;
|
|
67
|
+
class?: ClassValue;
|
|
68
|
+
className?: ClassValue;
|
|
69
|
+
style?: string | StyleObject;
|
|
70
|
+
dangerouslySetInnerHTML?: {
|
|
71
|
+
__html: string;
|
|
72
|
+
};
|
|
73
|
+
[attribute: string]: unknown;
|
|
74
|
+
}
|
|
75
|
+
declare namespace JSX {
|
|
76
|
+
type Element = OrielElement;
|
|
77
|
+
/** Lets components be async: `async function Posts() { … }` is a valid element type. */
|
|
78
|
+
type ElementType = string | Component<never>;
|
|
79
|
+
interface ElementChildrenAttribute {
|
|
80
|
+
children: unknown;
|
|
81
|
+
}
|
|
82
|
+
interface IntrinsicAttributes {
|
|
83
|
+
key?: string | number;
|
|
84
|
+
}
|
|
85
|
+
interface IntrinsicElements {
|
|
86
|
+
[element: string]: HtmlAttributes;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Programmer errors (Laravel throws InvalidArgumentException for these). Not an HTTP condition, so kind 'Server':
|
|
92
|
+
* the exception handler reports them and renders a 500 whose message is hidden unless app.debug is on.
|
|
93
|
+
*/
|
|
94
|
+
declare class ViewRenderError extends Error implements OrielError {
|
|
95
|
+
readonly name: string;
|
|
96
|
+
readonly kind: ErrorKind;
|
|
97
|
+
readonly status = 500;
|
|
98
|
+
}
|
|
99
|
+
/** Laravel's "View [x] not found." (InvalidArgumentException). */
|
|
100
|
+
declare class ViewNotFoundError extends Error implements OrielError {
|
|
101
|
+
readonly view: string;
|
|
102
|
+
readonly searched: string[];
|
|
103
|
+
readonly name: string;
|
|
104
|
+
readonly kind: ErrorKind;
|
|
105
|
+
readonly status = 500;
|
|
106
|
+
constructor(view: string, searched?: string[]);
|
|
107
|
+
}
|
|
108
|
+
/** A view file that doesn't default-export a component. */
|
|
109
|
+
declare class InvalidViewError extends Error implements OrielError {
|
|
110
|
+
readonly name: string;
|
|
111
|
+
readonly kind: ErrorKind;
|
|
112
|
+
readonly status = 500;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Laravel's FileViewFinder: 'posts.index' → <location>/posts/index.<ext> for the first location and extension
|
|
117
|
+
* that exist. Found paths are cached; misses are not, so a view created later is found.
|
|
118
|
+
*/
|
|
119
|
+
declare class FileViewFinder {
|
|
120
|
+
private readonly extensions;
|
|
121
|
+
static readonly defaultExtensions: string[];
|
|
122
|
+
private readonly locations;
|
|
123
|
+
private readonly hints;
|
|
124
|
+
private readonly views;
|
|
125
|
+
constructor(paths: string[], extensions?: string[]);
|
|
126
|
+
/** The absolute path of the view file. Throws ViewNotFoundError. */
|
|
127
|
+
find(name: string): string;
|
|
128
|
+
addLocation(path: string): void;
|
|
129
|
+
prependLocation(path: string): void;
|
|
130
|
+
/** Views under a namespace: addNamespace('mail', dir) makes 'mail::message' resolve to <dir>/message.tsx. */
|
|
131
|
+
addNamespace(namespace: string, hints: string | string[]): void;
|
|
132
|
+
replaceNamespace(namespace: string, hints: string | string[]): void;
|
|
133
|
+
getPaths(): string[];
|
|
134
|
+
getHints(): Record<string, string[]>;
|
|
135
|
+
/** Forget cached lookups. */
|
|
136
|
+
flush(): void;
|
|
137
|
+
/** [locations to search, relative file stem]. Dots become directories, so '..' can't climb out of a location. */
|
|
138
|
+
private parse;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** What TsxView needs from its factory. */
|
|
142
|
+
interface ViewEnvironment {
|
|
143
|
+
getShared(): Record<string, unknown>;
|
|
144
|
+
callComposer(view: View$1): Promise<void>;
|
|
145
|
+
load(path: string, name: string): Promise<Component>;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* One view: its name, file and data. render() runs the composers, imports the file and renders its default
|
|
149
|
+
* export with { ...shared, ...data } as props. toHtml() returns the HTML of the last render().
|
|
150
|
+
*/
|
|
151
|
+
declare class TsxView implements View$1 {
|
|
152
|
+
private readonly environment;
|
|
153
|
+
readonly name: string;
|
|
154
|
+
readonly path: string;
|
|
155
|
+
private data;
|
|
156
|
+
private html;
|
|
157
|
+
constructor(environment: ViewEnvironment, name: string, path: string, data?: Record<string, unknown>);
|
|
158
|
+
with(key: string | Record<string, unknown>, value?: unknown): this;
|
|
159
|
+
/** The view's own data (Laravel's getData()). */
|
|
160
|
+
getData(): Record<string, unknown>;
|
|
161
|
+
/** Shared data overlaid with the view's data: exactly the props the component receives. */
|
|
162
|
+
gatherData(): Record<string, unknown>;
|
|
163
|
+
render(): Promise<string>;
|
|
164
|
+
toHtml(): string;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
type Composer = (view: View$1) => void | Promise<void>;
|
|
168
|
+
/** Laravel's view Factory: finds views by dotted name, shares data app-wide and runs view composers. */
|
|
169
|
+
declare class Factory implements ViewFactory, ViewEnvironment {
|
|
170
|
+
private readonly finder;
|
|
171
|
+
private readonly shared;
|
|
172
|
+
private readonly composers;
|
|
173
|
+
constructor(finder: FileViewFinder);
|
|
174
|
+
/** Throws ViewNotFoundError ("View [x] not found.") when no file matches. */
|
|
175
|
+
make(name: string, data?: Record<string, unknown>): TsxView;
|
|
176
|
+
/** The first view that exists (Laravel's View::first()). */
|
|
177
|
+
first(names: string[], data?: Record<string, unknown>): TsxView;
|
|
178
|
+
exists(name: string): boolean;
|
|
179
|
+
/** App-wide data every view receives as props (view data wins on conflicts). */
|
|
180
|
+
share(key: string | Record<string, unknown>, value?: unknown): void;
|
|
181
|
+
getShared(): Record<string, unknown>;
|
|
182
|
+
/** Runs before matching views render. Patterns use `*` wildcards: 'posts.*', '*'. */
|
|
183
|
+
composer(views: string | string[], composer: Composer): void;
|
|
184
|
+
callComposer(view: View$1): Promise<void>;
|
|
185
|
+
/** Imports the view file (Node's module cache keeps it) and returns its default-export component. */
|
|
186
|
+
load(path: string, name: string): Promise<Component>;
|
|
187
|
+
addLocation(path: string): void;
|
|
188
|
+
addNamespace(namespace: string, hints: string | string[]): this;
|
|
189
|
+
getFinder(): FileViewFinder;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** view() → the ViewFactory; view('posts.index', data) → a View to return from a route or render. */
|
|
193
|
+
declare function view(): ViewFactory;
|
|
194
|
+
declare function view(name: string, data?: Record<string, unknown>): View$1;
|
|
195
|
+
/** Blade's @csrf / csrf_field(): the hidden _token input for the current request's session. */
|
|
196
|
+
declare function csrfField(): HtmlString;
|
|
197
|
+
/** Blade's @method('PUT') / method_field(): spoofs PUT/PATCH/DELETE from an HTML form. */
|
|
198
|
+
declare function methodField(method: string): HtmlString;
|
|
199
|
+
|
|
200
|
+
/** The View facade: View.make(), View.exists(), View.share(), View.composer(), View.first(), View.addNamespace(). */
|
|
201
|
+
declare const View: _orieljs_support.Facade<Factory, object>;
|
|
202
|
+
|
|
203
|
+
/** Binds the ViewFactory (resources/views by default) and merges the `view` config, like Laravel's config/view.php. */
|
|
204
|
+
declare class ViewServiceProvider extends ServiceProvider {
|
|
205
|
+
register(): void;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export { type ClassValue, type Component, ELEMENT, Factory, FileViewFinder, Fragment, type HtmlAttributes, HtmlString, InvalidViewError, JSX, type OrielElement, type Props, type Renderable, type StyleObject, TsxView, View, type ViewEnvironment, ViewNotFoundError, ViewRenderError, ViewServiceProvider, classNames, createElement, csrfField, e, isElement, isHtmlable, jsx, jsxs, methodField, raw, renderToStream, renderToString, styleString, view };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,481 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ELEMENT,
|
|
3
|
+
Fragment,
|
|
4
|
+
createElement,
|
|
5
|
+
isElement,
|
|
6
|
+
jsx,
|
|
7
|
+
jsxs
|
|
8
|
+
} from "./chunk-KIU7OKDI.js";
|
|
9
|
+
|
|
10
|
+
// Html.ts
|
|
11
|
+
var ESCAPES = { "&": "&", "<": "<", ">": ">", '"': """, "'": "'" };
|
|
12
|
+
var UNSAFE = /[&<>"']/g;
|
|
13
|
+
var HtmlString = class {
|
|
14
|
+
constructor(html = "") {
|
|
15
|
+
this.html = html;
|
|
16
|
+
}
|
|
17
|
+
html;
|
|
18
|
+
toHtml() {
|
|
19
|
+
return this.html;
|
|
20
|
+
}
|
|
21
|
+
toString() {
|
|
22
|
+
return this.html;
|
|
23
|
+
}
|
|
24
|
+
isEmpty() {
|
|
25
|
+
return this.html === "";
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
function raw(html) {
|
|
29
|
+
return new HtmlString(html);
|
|
30
|
+
}
|
|
31
|
+
function isHtmlable(value) {
|
|
32
|
+
return typeof value === "object" && value !== null && typeof value.toHtml === "function";
|
|
33
|
+
}
|
|
34
|
+
function e(value) {
|
|
35
|
+
if (value === null || value === void 0) return "";
|
|
36
|
+
if (isHtmlable(value)) return value.toHtml();
|
|
37
|
+
return String(value).replace(UNSAFE, (char) => ESCAPES[char]);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// errors.ts
|
|
41
|
+
var ViewRenderError = class extends Error {
|
|
42
|
+
name = "ViewRenderError";
|
|
43
|
+
kind = "Server";
|
|
44
|
+
status = 500;
|
|
45
|
+
};
|
|
46
|
+
var ViewNotFoundError = class extends Error {
|
|
47
|
+
constructor(view2, searched = []) {
|
|
48
|
+
super(`View [${view2}] not found.`);
|
|
49
|
+
this.view = view2;
|
|
50
|
+
this.searched = searched;
|
|
51
|
+
}
|
|
52
|
+
view;
|
|
53
|
+
searched;
|
|
54
|
+
name = "ViewNotFoundError";
|
|
55
|
+
kind = "Server";
|
|
56
|
+
status = 500;
|
|
57
|
+
};
|
|
58
|
+
var InvalidViewError = class extends Error {
|
|
59
|
+
name = "InvalidViewError";
|
|
60
|
+
kind = "Server";
|
|
61
|
+
status = 500;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// attributes.ts
|
|
65
|
+
var SKIPPED = /* @__PURE__ */ new Set(["children", "dangerouslySetInnerHTML", "key", "ref"]);
|
|
66
|
+
var RENAMED = { className: "class", htmlFor: "for" };
|
|
67
|
+
var VALID_NAME = /^[^\s"'<>/=\u0000-\u001f\u007f]+$/;
|
|
68
|
+
var UNITLESS = /* @__PURE__ */ new Set([
|
|
69
|
+
"animation-iteration-count",
|
|
70
|
+
"aspect-ratio",
|
|
71
|
+
"border-image-outset",
|
|
72
|
+
"border-image-slice",
|
|
73
|
+
"border-image-width",
|
|
74
|
+
"column-count",
|
|
75
|
+
"columns",
|
|
76
|
+
"fill-opacity",
|
|
77
|
+
"flex",
|
|
78
|
+
"flex-grow",
|
|
79
|
+
"flex-shrink",
|
|
80
|
+
"flex-order",
|
|
81
|
+
"font-weight",
|
|
82
|
+
"grid-area",
|
|
83
|
+
"grid-column",
|
|
84
|
+
"grid-column-end",
|
|
85
|
+
"grid-column-start",
|
|
86
|
+
"grid-row",
|
|
87
|
+
"grid-row-end",
|
|
88
|
+
"grid-row-start",
|
|
89
|
+
"line-clamp",
|
|
90
|
+
"line-height",
|
|
91
|
+
"opacity",
|
|
92
|
+
"order",
|
|
93
|
+
"orphans",
|
|
94
|
+
"scale",
|
|
95
|
+
"stop-opacity",
|
|
96
|
+
"stroke-dashoffset",
|
|
97
|
+
"stroke-opacity",
|
|
98
|
+
"stroke-width",
|
|
99
|
+
"tab-size",
|
|
100
|
+
"widows",
|
|
101
|
+
"z-index",
|
|
102
|
+
"zoom"
|
|
103
|
+
]);
|
|
104
|
+
function classNames(value) {
|
|
105
|
+
if (value === null || value === void 0 || value === false || value === "") return "";
|
|
106
|
+
if (typeof value === "string" || typeof value === "number") return String(value).trim();
|
|
107
|
+
if (Array.isArray(value)) return value.map(classNames).filter((name) => name !== "").join(" ");
|
|
108
|
+
return Object.entries(value).filter(([, on]) => Boolean(on)).map(([name]) => name).join(" ");
|
|
109
|
+
}
|
|
110
|
+
var kebab = (property) => property.startsWith("--") ? property : property.replace(/^ms([A-Z])/, "-ms-$1").replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`);
|
|
111
|
+
function styleString(style) {
|
|
112
|
+
const parts = [];
|
|
113
|
+
for (const [property, value] of Object.entries(style)) {
|
|
114
|
+
if (value === null || value === void 0 || value === false || value === "") continue;
|
|
115
|
+
const name = kebab(property);
|
|
116
|
+
const text = typeof value === "number" && value !== 0 && !UNITLESS.has(name) && !name.startsWith("--") ? `${value}px` : String(value);
|
|
117
|
+
parts.push(`${name}:${text}`);
|
|
118
|
+
}
|
|
119
|
+
return parts.join(";");
|
|
120
|
+
}
|
|
121
|
+
function assertValidName(name, what) {
|
|
122
|
+
if (!VALID_NAME.test(name)) throw new ViewRenderError(`Invalid ${what} name [${name}].`);
|
|
123
|
+
}
|
|
124
|
+
function renderAttributes(props) {
|
|
125
|
+
let out = "";
|
|
126
|
+
let classes = "";
|
|
127
|
+
for (const [prop, value] of Object.entries(props)) {
|
|
128
|
+
if (SKIPPED.has(prop)) continue;
|
|
129
|
+
if (value === void 0 || value === null) continue;
|
|
130
|
+
if (typeof value === "function" || typeof value === "symbol") continue;
|
|
131
|
+
const name = RENAMED[prop] ?? prop;
|
|
132
|
+
assertValidName(name, "attribute");
|
|
133
|
+
if (typeof value === "boolean" && (name.startsWith("aria-") || name.startsWith("data-"))) {
|
|
134
|
+
out += ` ${name}="${value}"`;
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
if (value === false) continue;
|
|
138
|
+
if (name === "class") {
|
|
139
|
+
const joined = classNames(value);
|
|
140
|
+
classes = classes === "" ? joined : joined === "" ? classes : `${classes} ${joined}`;
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
if (value === true) {
|
|
144
|
+
out += ` ${name}`;
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
const text = name === "style" && typeof value === "object" ? styleString(value) : attributeText(value);
|
|
148
|
+
out += ` ${name}="${e(text)}"`;
|
|
149
|
+
}
|
|
150
|
+
return classes === "" ? out : ` class="${e(classes)}"${out}`;
|
|
151
|
+
}
|
|
152
|
+
function attributeText(value) {
|
|
153
|
+
if (typeof value !== "object" || value === null) return String(value);
|
|
154
|
+
if (isHtmlable(value)) return value.toHtml();
|
|
155
|
+
if (value instanceof Date) return value.toISOString();
|
|
156
|
+
return JSON.stringify(value);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// render.ts
|
|
160
|
+
var VOID = /* @__PURE__ */ new Set(["area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "source", "track", "wbr"]);
|
|
161
|
+
var isThenable = (value) => typeof value === "object" && value !== null && typeof value.then === "function";
|
|
162
|
+
var isRenderer = (value) => typeof value.render === "function" && isHtmlable(value);
|
|
163
|
+
async function write(node, sink) {
|
|
164
|
+
if (node === null || node === void 0 || typeof node === "boolean") return;
|
|
165
|
+
if (typeof node === "string") return sink.write(e(node));
|
|
166
|
+
if (typeof node === "number" || typeof node === "bigint") return sink.write(String(node));
|
|
167
|
+
if (isElement(node)) return writeElement(node, sink);
|
|
168
|
+
if (isThenable(node)) {
|
|
169
|
+
sink.flush();
|
|
170
|
+
const resolved = await node;
|
|
171
|
+
return write(resolved, sink);
|
|
172
|
+
}
|
|
173
|
+
if (isRenderer(node)) {
|
|
174
|
+
sink.flush();
|
|
175
|
+
return sink.write(await node.render());
|
|
176
|
+
}
|
|
177
|
+
if (isHtmlable(node)) return sink.write(node.toHtml());
|
|
178
|
+
if (typeof node[Symbol.iterator] === "function") {
|
|
179
|
+
for (const child of node) await write(child, sink);
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
throw new ViewRenderError(`Objects are not valid as a child (found: object with keys {${Object.keys(node).join(", ")}}).`);
|
|
183
|
+
}
|
|
184
|
+
async function writeElement(element, sink) {
|
|
185
|
+
const { type, props } = element;
|
|
186
|
+
if (type === Fragment) return write(props.children, sink);
|
|
187
|
+
if (typeof type === "function") {
|
|
188
|
+
const result = type(props);
|
|
189
|
+
if (isThenable(result)) sink.flush();
|
|
190
|
+
const resolved = await result;
|
|
191
|
+
return write(resolved, sink);
|
|
192
|
+
}
|
|
193
|
+
if (typeof type !== "string") throw new ViewRenderError(`Invalid element type [${String(type)}].`);
|
|
194
|
+
assertValidName(type, "tag");
|
|
195
|
+
const inner = props.dangerouslySetInnerHTML;
|
|
196
|
+
const hasChildren = props.children !== void 0 && props.children !== null;
|
|
197
|
+
if (inner !== void 0 && hasChildren) {
|
|
198
|
+
throw new ViewRenderError(`<${type}> can't have both children and dangerouslySetInnerHTML.`);
|
|
199
|
+
}
|
|
200
|
+
if (type === "html") sink.write("<!DOCTYPE html>");
|
|
201
|
+
sink.write(`<${type}${renderAttributes(props)}>`);
|
|
202
|
+
if (VOID.has(type.toLowerCase())) {
|
|
203
|
+
if (hasChildren || inner !== void 0) throw new ViewRenderError(`<${type}> is a void element and can't have children.`);
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
if (inner !== void 0) sink.write(String(inner.__html ?? ""));
|
|
207
|
+
else await write(props.children, sink);
|
|
208
|
+
sink.write(`</${type}>`);
|
|
209
|
+
}
|
|
210
|
+
async function renderToString(node) {
|
|
211
|
+
const parts = [];
|
|
212
|
+
await write(node, { write: (html) => void parts.push(html), flush: () => {
|
|
213
|
+
} });
|
|
214
|
+
return parts.join("");
|
|
215
|
+
}
|
|
216
|
+
function renderToStream(node) {
|
|
217
|
+
const encoder = new TextEncoder();
|
|
218
|
+
return new ReadableStream({
|
|
219
|
+
async start(controller) {
|
|
220
|
+
let buffer = "";
|
|
221
|
+
const sink = {
|
|
222
|
+
write: (html) => void (buffer += html),
|
|
223
|
+
flush: () => {
|
|
224
|
+
if (buffer === "") return;
|
|
225
|
+
controller.enqueue(encoder.encode(buffer));
|
|
226
|
+
buffer = "";
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
try {
|
|
230
|
+
await write(node, sink);
|
|
231
|
+
sink.flush();
|
|
232
|
+
controller.close();
|
|
233
|
+
} catch (error) {
|
|
234
|
+
controller.error(error);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// FileViewFinder.ts
|
|
241
|
+
import { existsSync } from "fs";
|
|
242
|
+
import { isAbsolute, join, resolve } from "path";
|
|
243
|
+
var HINT = "::";
|
|
244
|
+
var FileViewFinder = class _FileViewFinder {
|
|
245
|
+
constructor(paths, extensions = _FileViewFinder.defaultExtensions) {
|
|
246
|
+
this.extensions = extensions;
|
|
247
|
+
this.locations = paths.map((path) => resolve(path));
|
|
248
|
+
}
|
|
249
|
+
extensions;
|
|
250
|
+
static defaultExtensions = ["tsx", "ts", "jsx", "js", "mjs"];
|
|
251
|
+
locations;
|
|
252
|
+
hints = /* @__PURE__ */ new Map();
|
|
253
|
+
views = /* @__PURE__ */ new Map();
|
|
254
|
+
/** The absolute path of the view file. Throws ViewNotFoundError. */
|
|
255
|
+
find(name) {
|
|
256
|
+
const cached = this.views.get(name);
|
|
257
|
+
if (cached !== void 0) return cached;
|
|
258
|
+
const [locations, view2] = this.parse(name);
|
|
259
|
+
const searched = [];
|
|
260
|
+
for (const location of locations) {
|
|
261
|
+
for (const extension of this.extensions) {
|
|
262
|
+
const file = join(location, `${view2}.${extension}`);
|
|
263
|
+
searched.push(file);
|
|
264
|
+
if (existsSync(file)) {
|
|
265
|
+
this.views.set(name, file);
|
|
266
|
+
return file;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
throw new ViewNotFoundError(name, searched);
|
|
271
|
+
}
|
|
272
|
+
addLocation(path) {
|
|
273
|
+
this.locations.push(resolve(path));
|
|
274
|
+
}
|
|
275
|
+
prependLocation(path) {
|
|
276
|
+
this.locations.unshift(resolve(path));
|
|
277
|
+
}
|
|
278
|
+
/** Views under a namespace: addNamespace('mail', dir) makes 'mail::message' resolve to <dir>/message.tsx. */
|
|
279
|
+
addNamespace(namespace, hints) {
|
|
280
|
+
const existing = this.hints.get(namespace) ?? [];
|
|
281
|
+
this.hints.set(namespace, [...existing, ...[hints].flat().map((path) => resolve(path))]);
|
|
282
|
+
}
|
|
283
|
+
replaceNamespace(namespace, hints) {
|
|
284
|
+
this.hints.set(namespace, [hints].flat().map((path) => resolve(path)));
|
|
285
|
+
this.flush();
|
|
286
|
+
}
|
|
287
|
+
getPaths() {
|
|
288
|
+
return [...this.locations];
|
|
289
|
+
}
|
|
290
|
+
getHints() {
|
|
291
|
+
return Object.fromEntries(this.hints);
|
|
292
|
+
}
|
|
293
|
+
/** Forget cached lookups. */
|
|
294
|
+
flush() {
|
|
295
|
+
this.views.clear();
|
|
296
|
+
}
|
|
297
|
+
/** [locations to search, relative file stem]. Dots become directories, so '..' can't climb out of a location. */
|
|
298
|
+
parse(name) {
|
|
299
|
+
let locations = this.locations;
|
|
300
|
+
let view2 = name;
|
|
301
|
+
const at = name.indexOf(HINT);
|
|
302
|
+
if (at !== -1) {
|
|
303
|
+
const namespace = name.slice(0, at);
|
|
304
|
+
view2 = name.slice(at + HINT.length);
|
|
305
|
+
const hints = this.hints.get(namespace);
|
|
306
|
+
if (hints === void 0) throw new ViewNotFoundError(name);
|
|
307
|
+
locations = hints;
|
|
308
|
+
}
|
|
309
|
+
const stem = view2.replaceAll(".", "/");
|
|
310
|
+
if (view2 === "" || stem.includes("\0") || isAbsolute(stem) || stem.split(/[\\/]/).some((segment) => segment === "")) {
|
|
311
|
+
throw new ViewNotFoundError(name);
|
|
312
|
+
}
|
|
313
|
+
return [locations, stem];
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
// TsxView.ts
|
|
318
|
+
var TsxView = class {
|
|
319
|
+
constructor(environment, name, path, data = {}) {
|
|
320
|
+
this.environment = environment;
|
|
321
|
+
this.name = name;
|
|
322
|
+
this.path = path;
|
|
323
|
+
this.data = { ...data };
|
|
324
|
+
}
|
|
325
|
+
environment;
|
|
326
|
+
name;
|
|
327
|
+
path;
|
|
328
|
+
data;
|
|
329
|
+
html;
|
|
330
|
+
with(key, value) {
|
|
331
|
+
if (typeof key === "string") this.data[key] = value;
|
|
332
|
+
else Object.assign(this.data, key);
|
|
333
|
+
return this;
|
|
334
|
+
}
|
|
335
|
+
/** The view's own data (Laravel's getData()). */
|
|
336
|
+
getData() {
|
|
337
|
+
return { ...this.data };
|
|
338
|
+
}
|
|
339
|
+
/** Shared data overlaid with the view's data: exactly the props the component receives. */
|
|
340
|
+
gatherData() {
|
|
341
|
+
return { ...this.environment.getShared(), ...this.data };
|
|
342
|
+
}
|
|
343
|
+
async render() {
|
|
344
|
+
await this.environment.callComposer(this);
|
|
345
|
+
const component = await this.environment.load(this.path, this.name);
|
|
346
|
+
this.html = await renderToString(createElement(component, this.gatherData()));
|
|
347
|
+
return this.html;
|
|
348
|
+
}
|
|
349
|
+
toHtml() {
|
|
350
|
+
if (this.html === void 0) {
|
|
351
|
+
throw new ViewRenderError(`View [${this.name}] has not been rendered: await view.render() before toHtml().`);
|
|
352
|
+
}
|
|
353
|
+
return this.html;
|
|
354
|
+
}
|
|
355
|
+
};
|
|
356
|
+
|
|
357
|
+
// Factory.ts
|
|
358
|
+
import { pathToFileURL } from "url";
|
|
359
|
+
import { Str } from "@orieljs/support";
|
|
360
|
+
var Factory = class {
|
|
361
|
+
constructor(finder) {
|
|
362
|
+
this.finder = finder;
|
|
363
|
+
}
|
|
364
|
+
finder;
|
|
365
|
+
shared = {};
|
|
366
|
+
composers = [];
|
|
367
|
+
/** Throws ViewNotFoundError ("View [x] not found.") when no file matches. */
|
|
368
|
+
make(name, data = {}) {
|
|
369
|
+
return new TsxView(this, name, this.finder.find(name), data);
|
|
370
|
+
}
|
|
371
|
+
/** The first view that exists (Laravel's View::first()). */
|
|
372
|
+
first(names, data = {}) {
|
|
373
|
+
const name = names.find((candidate) => this.exists(candidate));
|
|
374
|
+
if (name === void 0) throw new ViewNotFoundError(names.join(", "));
|
|
375
|
+
return this.make(name, data);
|
|
376
|
+
}
|
|
377
|
+
exists(name) {
|
|
378
|
+
try {
|
|
379
|
+
this.finder.find(name);
|
|
380
|
+
return true;
|
|
381
|
+
} catch (error) {
|
|
382
|
+
if (error instanceof ViewNotFoundError) return false;
|
|
383
|
+
throw error;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
/** App-wide data every view receives as props (view data wins on conflicts). */
|
|
387
|
+
share(key, value) {
|
|
388
|
+
if (typeof key === "string") this.shared[key] = value;
|
|
389
|
+
else Object.assign(this.shared, key);
|
|
390
|
+
}
|
|
391
|
+
getShared() {
|
|
392
|
+
return { ...this.shared };
|
|
393
|
+
}
|
|
394
|
+
/** Runs before matching views render. Patterns use `*` wildcards: 'posts.*', '*'. */
|
|
395
|
+
composer(views, composer) {
|
|
396
|
+
this.composers.push({ patterns: [views].flat(), composer });
|
|
397
|
+
}
|
|
398
|
+
async callComposer(view2) {
|
|
399
|
+
for (const { patterns, composer } of this.composers) {
|
|
400
|
+
if (patterns.some((pattern) => Str.is(pattern, view2.name))) await composer(view2);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
/** Imports the view file (Node's module cache keeps it) and returns its default-export component. */
|
|
404
|
+
async load(path, name) {
|
|
405
|
+
const module = await import(pathToFileURL(path).href);
|
|
406
|
+
if (typeof module.default !== "function") {
|
|
407
|
+
throw new InvalidViewError(`View [${name}] (${path}) must default-export a component function.`);
|
|
408
|
+
}
|
|
409
|
+
return module.default;
|
|
410
|
+
}
|
|
411
|
+
addLocation(path) {
|
|
412
|
+
this.finder.addLocation(path);
|
|
413
|
+
}
|
|
414
|
+
addNamespace(namespace, hints) {
|
|
415
|
+
this.finder.addNamespace(namespace, hints);
|
|
416
|
+
return this;
|
|
417
|
+
}
|
|
418
|
+
getFinder() {
|
|
419
|
+
return this.finder;
|
|
420
|
+
}
|
|
421
|
+
};
|
|
422
|
+
|
|
423
|
+
// helpers.ts
|
|
424
|
+
import { Session, ViewFactory } from "@orieljs/contracts";
|
|
425
|
+
import { inject } from "@orieljs/container";
|
|
426
|
+
function view(name, data = {}) {
|
|
427
|
+
const factory = inject(ViewFactory);
|
|
428
|
+
return name === void 0 ? factory : factory.make(name, data);
|
|
429
|
+
}
|
|
430
|
+
function csrfField() {
|
|
431
|
+
return new HtmlString(`<input type="hidden" name="_token" value="${e(inject(Session).token())}" autocomplete="off">`);
|
|
432
|
+
}
|
|
433
|
+
function methodField(method) {
|
|
434
|
+
return new HtmlString(`<input type="hidden" name="_method" value="${e(method.toUpperCase())}">`);
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
// facade.ts
|
|
438
|
+
import { ViewFactory as ViewFactory2 } from "@orieljs/contracts";
|
|
439
|
+
import { facade } from "@orieljs/support";
|
|
440
|
+
var View = facade(ViewFactory2);
|
|
441
|
+
|
|
442
|
+
// ViewServiceProvider.ts
|
|
443
|
+
import { ConfigRepository, ViewFactory as ViewFactory3 } from "@orieljs/contracts";
|
|
444
|
+
import { ServiceProvider } from "@orieljs/support";
|
|
445
|
+
var ViewServiceProvider = class extends ServiceProvider {
|
|
446
|
+
register() {
|
|
447
|
+
this.mergeConfigFrom({ paths: [this.app.resourcePath("views")] }, "view");
|
|
448
|
+
this.app.singleton(ViewFactory3, () => {
|
|
449
|
+
const paths = this.app.make(ConfigRepository).get("view.paths", [this.app.resourcePath("views")]);
|
|
450
|
+
return new Factory(new FileViewFinder(paths));
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
};
|
|
454
|
+
export {
|
|
455
|
+
ELEMENT,
|
|
456
|
+
Factory,
|
|
457
|
+
FileViewFinder,
|
|
458
|
+
Fragment,
|
|
459
|
+
HtmlString,
|
|
460
|
+
InvalidViewError,
|
|
461
|
+
TsxView,
|
|
462
|
+
View,
|
|
463
|
+
ViewNotFoundError,
|
|
464
|
+
ViewRenderError,
|
|
465
|
+
ViewServiceProvider,
|
|
466
|
+
classNames,
|
|
467
|
+
createElement,
|
|
468
|
+
csrfField,
|
|
469
|
+
e,
|
|
470
|
+
isElement,
|
|
471
|
+
isHtmlable,
|
|
472
|
+
jsx,
|
|
473
|
+
jsxs,
|
|
474
|
+
methodField,
|
|
475
|
+
raw,
|
|
476
|
+
renderToStream,
|
|
477
|
+
renderToString,
|
|
478
|
+
styleString,
|
|
479
|
+
view
|
|
480
|
+
};
|
|
481
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../Html.ts","../errors.ts","../attributes.ts","../render.ts","../FileViewFinder.ts","../TsxView.ts","../Factory.ts","../helpers.ts","../facade.ts","../ViewServiceProvider.ts"],"sourcesContent":["import type { Htmlable } from '@orieljs/contracts'\n\nconst ESCAPES: Record<string, string> = { '&': '&', '<': '<', '>': '>', '\"': '"', \"'\": ''' }\nconst UNSAFE = /[&<>\"']/g\n\n/** Markup that must not be escaped again (Laravel's Illuminate\\Support\\HtmlString). */\nexport class HtmlString implements Htmlable {\n constructor(private readonly html: string = '') {}\n\n toHtml(): string {\n return this.html\n }\n\n toString(): string {\n return this.html\n }\n\n isEmpty(): boolean {\n return this.html === ''\n }\n}\n\n/** Marks trusted markup so the renderer emits it unescaped: {raw(markdownHtml)}. Never pass user input. */\nexport function raw(html: string): HtmlString {\n return new HtmlString(html)\n}\n\nexport function isHtmlable(value: unknown): value is Htmlable {\n return typeof value === 'object' && value !== null && typeof (value as Htmlable).toHtml === 'function'\n}\n\n/** Laravel's e(): htmlspecialchars(ENT_QUOTES, double-encode). Htmlable values pass through; null is ''. */\nexport function e(value: unknown): string {\n if (value === null || value === undefined) return ''\n if (isHtmlable(value)) return value.toHtml()\n return String(value).replace(UNSAFE, (char) => ESCAPES[char]!)\n}\n","import type { ErrorKind, OrielError } from '@orieljs/contracts'\n\n/**\n * Programmer errors (Laravel throws InvalidArgumentException for these). Not an HTTP condition, so kind 'Server':\n * the exception handler reports them and renders a 500 whose message is hidden unless app.debug is on.\n */\nexport class ViewRenderError extends Error implements OrielError {\n override readonly name: string = 'ViewRenderError'\n readonly kind: ErrorKind = 'Server'\n readonly status = 500\n}\n\n/** Laravel's \"View [x] not found.\" (InvalidArgumentException). */\nexport class ViewNotFoundError extends Error implements OrielError {\n override readonly name: string = 'ViewNotFoundError'\n readonly kind: ErrorKind = 'Server'\n readonly status = 500\n constructor(readonly view: string, readonly searched: string[] = []) {\n super(`View [${view}] not found.`)\n }\n}\n\n/** A view file that doesn't default-export a component. */\nexport class InvalidViewError extends Error implements OrielError {\n override readonly name: string = 'InvalidViewError'\n readonly kind: ErrorKind = 'Server'\n readonly status = 500\n}\n","import { e, isHtmlable } from './Html'\nimport { ViewRenderError } from './errors'\n\n/** Props that are never attributes. */\nconst SKIPPED = new Set(['children', 'dangerouslySetInnerHTML', 'key', 'ref'])\n/** React-style prop names that map to a different HTML attribute. */\nconst RENAMED: Record<string, string> = { className: 'class', htmlFor: 'for' }\n/** HTML attribute names: no whitespace, quotes, `<`, `>`, `/`, `=` or control characters (WHATWG). */\nconst VALID_NAME = /^[^\\s\"'<>/=\\u0000-\\u001f\\u007f]+$/\n/** CSS properties whose numbers get no `px` (React's list, trimmed to what HTML pages use). */\nconst UNITLESS = new Set([\n 'animation-iteration-count', 'aspect-ratio', 'border-image-outset', 'border-image-slice', 'border-image-width',\n 'column-count', 'columns', 'fill-opacity', 'flex', 'flex-grow', 'flex-shrink', 'flex-order', 'font-weight',\n 'grid-area', 'grid-column', 'grid-column-end', 'grid-column-start', 'grid-row', 'grid-row-end', 'grid-row-start',\n 'line-clamp', 'line-height', 'opacity', 'order', 'orphans', 'scale', 'stop-opacity', 'stroke-dashoffset',\n 'stroke-opacity', 'stroke-width', 'tab-size', 'widows', 'z-index', 'zoom',\n])\n\nexport type ClassValue = string | number | null | undefined | false | ClassValue[] | Record<string, unknown>\nexport type StyleObject = Record<string, string | number | null | undefined | false>\n\n/** `class` accepts strings, arrays and `{ name: condition }` objects, like Blade's @class. */\nexport function classNames(value: ClassValue): string {\n if (value === null || value === undefined || value === false || value === '') return ''\n if (typeof value === 'string' || typeof value === 'number') return String(value).trim()\n if (Array.isArray(value)) return value.map(classNames).filter((name) => name !== '').join(' ')\n return Object.entries(value).filter(([, on]) => Boolean(on)).map(([name]) => name).join(' ')\n}\n\nconst kebab = (property: string) =>\n property.startsWith('--') ? property : property.replace(/^ms([A-Z])/, '-ms-$1').replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`)\n\n/** `{ marginTop: 4, '--gap': '1rem' }` → `margin-top:4px;--gap:1rem`. */\nexport function styleString(style: StyleObject): string {\n const parts: string[] = []\n for (const [property, value] of Object.entries(style)) {\n if (value === null || value === undefined || value === false || value === '') continue\n const name = kebab(property)\n const text = typeof value === 'number' && value !== 0 && !UNITLESS.has(name) && !name.startsWith('--') ? `${value}px` : String(value)\n parts.push(`${name}:${text}`)\n }\n return parts.join(';')\n}\n\nexport function assertValidName(name: string, what: 'attribute' | 'tag'): void {\n if (!VALID_NAME.test(name)) throw new ViewRenderError(`Invalid ${what} name [${name}].`)\n}\n\n/** Serializes props to ` name=\"value\"` pairs. Every value is escaped (HtmlString too); names are validated, never escaped. */\nexport function renderAttributes(props: Record<string, unknown>): string {\n let out = ''\n let classes = ''\n for (const [prop, value] of Object.entries(props)) {\n if (SKIPPED.has(prop)) continue\n if (value === undefined || value === null) continue\n if (typeof value === 'function' || typeof value === 'symbol') continue // event handlers do nothing on the server\n const name = RENAMED[prop] ?? prop\n assertValidName(name, 'attribute')\n // aria-*/data-* are string attributes: booleans are written out, like React.\n if (typeof value === 'boolean' && (name.startsWith('aria-') || name.startsWith('data-'))) {\n out += ` ${name}=\"${value}\"`\n continue\n }\n if (value === false) continue\n if (name === 'class') {\n const joined = classNames(value as ClassValue)\n classes = classes === '' ? joined : joined === '' ? classes : `${classes} ${joined}`\n continue\n }\n // Boolean attributes (disabled, checked, …) are present or absent.\n if (value === true) {\n out += ` ${name}`\n continue\n }\n const text = name === 'style' && typeof value === 'object' ? styleString(value as StyleObject) : attributeText(value)\n out += ` ${name}=\"${e(text)}\"`\n }\n return classes === '' ? out : ` class=\"${e(classes)}\"${out}`\n}\n\n/** Attribute values are text: objects become JSON (x-data, data-*), Htmlable its markup; the caller escapes all of it. */\nfunction attributeText(value: unknown): string {\n if (typeof value !== 'object' || value === null) return String(value)\n if (isHtmlable(value)) return value.toHtml()\n if (value instanceof Date) return value.toISOString()\n return JSON.stringify(value)\n}\n","import { Fragment, isElement, type OrielElement, type Renderable } from './Element'\nimport { e, isHtmlable } from './Html'\nimport { assertValidName, renderAttributes } from './attributes'\nimport { ViewRenderError } from './errors'\n\n/** Elements that never have children or a closing tag. */\nconst VOID = new Set(['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'source', 'track', 'wbr'])\n\n/** Where rendered HTML goes. flush() is called before every await, so a stream sends what is ready. */\ninterface Sink {\n write(html: string): void\n flush(): void\n}\n\ninterface Renderer {\n render(): Promise<string>\n}\n\nconst isThenable = (value: unknown): value is PromiseLike<unknown> =>\n typeof value === 'object' && value !== null && typeof (value as PromiseLike<unknown>).then === 'function'\n\n/** A View (or anything with an async render() and toHtml()) used as a child, like Blade's @include. */\nconst isRenderer = (value: object): value is Renderer =>\n typeof (value as Partial<Renderer>).render === 'function' && isHtmlable(value)\n\nasync function write(node: Renderable, sink: Sink): Promise<void> {\n if (node === null || node === undefined || typeof node === 'boolean') return\n if (typeof node === 'string') return sink.write(e(node))\n if (typeof node === 'number' || typeof node === 'bigint') return sink.write(String(node))\n if (isElement(node)) return writeElement(node, sink)\n if (isThenable(node)) {\n sink.flush()\n const resolved: unknown = await (node as PromiseLike<unknown>)\n return write(resolved as Renderable, sink)\n }\n if (isRenderer(node)) {\n sink.flush()\n return sink.write(await node.render())\n }\n if (isHtmlable(node)) return sink.write(node.toHtml())\n if (typeof (node as Iterable<Renderable>)[Symbol.iterator] === 'function') {\n for (const child of node as Iterable<Renderable>) await write(child, sink)\n return\n }\n throw new ViewRenderError(`Objects are not valid as a child (found: object with keys {${Object.keys(node).join(', ')}}).`)\n}\n\nasync function writeElement(element: OrielElement, sink: Sink): Promise<void> {\n const { type, props } = element\n if (type === Fragment) return write(props.children as Renderable, sink)\n if (typeof type === 'function') {\n const result = (type as (props: unknown) => unknown)(props)\n if (isThenable(result)) sink.flush()\n const resolved: unknown = await result\n return write(resolved as Renderable, sink)\n }\n if (typeof type !== 'string') throw new ViewRenderError(`Invalid element type [${String(type)}].`)\n assertValidName(type, 'tag')\n\n const inner = props.dangerouslySetInnerHTML as { __html?: unknown } | undefined\n const hasChildren = props.children !== undefined && props.children !== null\n if (inner !== undefined && hasChildren) {\n throw new ViewRenderError(`<${type}> can't have both children and dangerouslySetInnerHTML.`)\n }\n // A document root gets its doctype: TSX has no syntax for <!DOCTYPE html>.\n if (type === 'html') sink.write('<!DOCTYPE html>')\n sink.write(`<${type}${renderAttributes(props)}>`)\n if (VOID.has(type.toLowerCase())) {\n if (hasChildren || inner !== undefined) throw new ViewRenderError(`<${type}> is a void element and can't have children.`)\n return\n }\n if (inner !== undefined) sink.write(String(inner.__html ?? ''))\n else await write(props.children as Renderable, sink)\n sink.write(`</${type}>`)\n}\n\n/** Renders JSX (or any Renderable) to an HTML string. Async components and promises are awaited in order. */\nexport async function renderToString(node: Renderable): Promise<string> {\n const parts: string[] = []\n await write(node, { write: (html) => void parts.push(html), flush: () => {} })\n return parts.join('')\n}\n\n/** Renders to a UTF-8 byte stream, sending everything rendered so far each time rendering waits on a promise. */\nexport function renderToStream(node: Renderable): ReadableStream<Uint8Array> {\n const encoder = new TextEncoder()\n return new ReadableStream<Uint8Array>({\n async start(controller) {\n let buffer = ''\n const sink: Sink = {\n write: (html) => void (buffer += html),\n flush: () => {\n if (buffer === '') return\n controller.enqueue(encoder.encode(buffer))\n buffer = ''\n },\n }\n try {\n await write(node, sink)\n sink.flush()\n controller.close()\n } catch (error) {\n controller.error(error)\n }\n },\n })\n}\n","import { existsSync } from 'node:fs'\nimport { isAbsolute, join, resolve } from 'node:path'\nimport { ViewNotFoundError } from './errors'\n\n/** `mail::message` → namespace `mail`, view `message` (Laravel's hint path delimiter). */\nconst HINT = '::'\n\n/**\n * Laravel's FileViewFinder: 'posts.index' → <location>/posts/index.<ext> for the first location and extension\n * that exist. Found paths are cached; misses are not, so a view created later is found.\n */\nexport class FileViewFinder {\n static readonly defaultExtensions = ['tsx', 'ts', 'jsx', 'js', 'mjs']\n\n private readonly locations: string[]\n private readonly hints = new Map<string, string[]>()\n private readonly views = new Map<string, string>()\n\n constructor(paths: string[], private readonly extensions: string[] = FileViewFinder.defaultExtensions) {\n this.locations = paths.map((path) => resolve(path))\n }\n\n /** The absolute path of the view file. Throws ViewNotFoundError. */\n find(name: string): string {\n const cached = this.views.get(name)\n if (cached !== undefined) return cached\n const [locations, view] = this.parse(name)\n const searched: string[] = []\n for (const location of locations) {\n for (const extension of this.extensions) {\n const file = join(location, `${view}.${extension}`)\n searched.push(file)\n if (existsSync(file)) {\n this.views.set(name, file)\n return file\n }\n }\n }\n throw new ViewNotFoundError(name, searched)\n }\n\n addLocation(path: string): void {\n this.locations.push(resolve(path))\n }\n\n prependLocation(path: string): void {\n this.locations.unshift(resolve(path))\n }\n\n /** Views under a namespace: addNamespace('mail', dir) makes 'mail::message' resolve to <dir>/message.tsx. */\n addNamespace(namespace: string, hints: string | string[]): void {\n const existing = this.hints.get(namespace) ?? []\n this.hints.set(namespace, [...existing, ...[hints].flat().map((path) => resolve(path))])\n }\n\n replaceNamespace(namespace: string, hints: string | string[]): void {\n this.hints.set(namespace, [hints].flat().map((path) => resolve(path)))\n this.flush()\n }\n\n getPaths(): string[] {\n return [...this.locations]\n }\n\n getHints(): Record<string, string[]> {\n return Object.fromEntries(this.hints)\n }\n\n /** Forget cached lookups. */\n flush(): void {\n this.views.clear()\n }\n\n /** [locations to search, relative file stem]. Dots become directories, so '..' can't climb out of a location. */\n private parse(name: string): [string[], string] {\n let locations = this.locations\n let view = name\n const at = name.indexOf(HINT)\n if (at !== -1) {\n const namespace = name.slice(0, at)\n view = name.slice(at + HINT.length)\n const hints = this.hints.get(namespace)\n if (hints === undefined) throw new ViewNotFoundError(name)\n locations = hints\n }\n const stem = view.replaceAll('.', '/')\n if (view === '' || stem.includes('\\0') || isAbsolute(stem) || stem.split(/[\\\\/]/).some((segment) => segment === '')) {\n throw new ViewNotFoundError(name)\n }\n return [locations, stem]\n }\n}\n","import type { View } from '@orieljs/contracts'\nimport { createElement, type Component } from './Element'\nimport { ViewRenderError } from './errors'\nimport { renderToString } from './render'\n\n/** What TsxView needs from its factory. */\nexport interface ViewEnvironment {\n getShared(): Record<string, unknown>\n callComposer(view: View): Promise<void>\n load(path: string, name: string): Promise<Component>\n}\n\n/**\n * One view: its name, file and data. render() runs the composers, imports the file and renders its default\n * export with { ...shared, ...data } as props. toHtml() returns the HTML of the last render().\n */\nexport class TsxView implements View {\n private data: Record<string, unknown>\n private html: string | undefined\n\n constructor(\n private readonly environment: ViewEnvironment,\n readonly name: string,\n readonly path: string,\n data: Record<string, unknown> = {},\n ) {\n this.data = { ...data }\n }\n\n with(key: string | Record<string, unknown>, value?: unknown): this {\n if (typeof key === 'string') this.data[key] = value\n else Object.assign(this.data, key)\n return this\n }\n\n /** The view's own data (Laravel's getData()). */\n getData(): Record<string, unknown> {\n return { ...this.data }\n }\n\n /** Shared data overlaid with the view's data: exactly the props the component receives. */\n gatherData(): Record<string, unknown> {\n return { ...this.environment.getShared(), ...this.data }\n }\n\n async render(): Promise<string> {\n await this.environment.callComposer(this)\n const component = await this.environment.load(this.path, this.name)\n this.html = await renderToString(createElement(component as Component<never>, this.gatherData()))\n return this.html\n }\n\n toHtml(): string {\n if (this.html === undefined) {\n throw new ViewRenderError(`View [${this.name}] has not been rendered: await view.render() before toHtml().`)\n }\n return this.html\n }\n}\n","import { pathToFileURL } from 'node:url'\nimport type { View, ViewFactory } from '@orieljs/contracts'\nimport { Str } from '@orieljs/support'\nimport type { Component } from './Element'\nimport { InvalidViewError, ViewNotFoundError } from './errors'\nimport type { FileViewFinder } from './FileViewFinder'\nimport { TsxView, type ViewEnvironment } from './TsxView'\n\ntype Composer = (view: View) => void | Promise<void>\n\n/** Laravel's view Factory: finds views by dotted name, shares data app-wide and runs view composers. */\nexport class Factory implements ViewFactory, ViewEnvironment {\n private readonly shared: Record<string, unknown> = {}\n private readonly composers: Array<{ patterns: string[]; composer: Composer }> = []\n\n constructor(private readonly finder: FileViewFinder) {}\n\n /** Throws ViewNotFoundError (\"View [x] not found.\") when no file matches. */\n make(name: string, data: Record<string, unknown> = {}): TsxView {\n return new TsxView(this, name, this.finder.find(name), data)\n }\n\n /** The first view that exists (Laravel's View::first()). */\n first(names: string[], data: Record<string, unknown> = {}): TsxView {\n const name = names.find((candidate) => this.exists(candidate))\n if (name === undefined) throw new ViewNotFoundError(names.join(', '))\n return this.make(name, data)\n }\n\n exists(name: string): boolean {\n try {\n this.finder.find(name)\n return true\n } catch (error) {\n if (error instanceof ViewNotFoundError) return false\n throw error\n }\n }\n\n /** App-wide data every view receives as props (view data wins on conflicts). */\n share(key: string | Record<string, unknown>, value?: unknown): void {\n if (typeof key === 'string') this.shared[key] = value\n else Object.assign(this.shared, key)\n }\n\n getShared(): Record<string, unknown> {\n return { ...this.shared }\n }\n\n /** Runs before matching views render. Patterns use `*` wildcards: 'posts.*', '*'. */\n composer(views: string | string[], composer: Composer): void {\n this.composers.push({ patterns: [views].flat(), composer })\n }\n\n async callComposer(view: View): Promise<void> {\n for (const { patterns, composer } of this.composers) {\n if (patterns.some((pattern) => Str.is(pattern, view.name))) await composer(view)\n }\n }\n\n /** Imports the view file (Node's module cache keeps it) and returns its default-export component. */\n async load(path: string, name: string): Promise<Component> {\n const module = (await import(pathToFileURL(path).href)) as { default?: unknown }\n if (typeof module.default !== 'function') {\n throw new InvalidViewError(`View [${name}] (${path}) must default-export a component function.`)\n }\n return module.default as Component\n }\n\n addLocation(path: string): void {\n this.finder.addLocation(path)\n }\n\n addNamespace(namespace: string, hints: string | string[]): this {\n this.finder.addNamespace(namespace, hints)\n return this\n }\n\n getFinder(): FileViewFinder {\n return this.finder\n }\n}\n","import { Session, ViewFactory, type View } from '@orieljs/contracts'\nimport { inject } from '@orieljs/container'\nimport { e, HtmlString } from './Html'\n\n/** view() → the ViewFactory; view('posts.index', data) → a View to return from a route or render. */\nexport function view(): ViewFactory\nexport function view(name: string, data?: Record<string, unknown>): View\nexport function view(name?: string, data: Record<string, unknown> = {}): ViewFactory | View {\n const factory = inject(ViewFactory)\n return name === undefined ? factory : factory.make(name, data)\n}\n\n/** Blade's @csrf / csrf_field(): the hidden _token input for the current request's session. */\nexport function csrfField(): HtmlString {\n return new HtmlString(`<input type=\"hidden\" name=\"_token\" value=\"${e(inject(Session).token())}\" autocomplete=\"off\">`)\n}\n\n/** Blade's @method('PUT') / method_field(): spoofs PUT/PATCH/DELETE from an HTML form. */\nexport function methodField(method: string): HtmlString {\n return new HtmlString(`<input type=\"hidden\" name=\"_method\" value=\"${e(method.toUpperCase())}\">`)\n}\n","import { ViewFactory, type Token } from '@orieljs/contracts'\nimport { facade } from '@orieljs/support'\nimport type { Factory } from './Factory'\n\n/** The View facade: View.make(), View.exists(), View.share(), View.composer(), View.first(), View.addNamespace(). */\nexport const View = facade(ViewFactory as unknown as Token<Factory>)\n","import { ConfigRepository, ViewFactory } from '@orieljs/contracts'\nimport { ServiceProvider } from '@orieljs/support'\nimport { Factory } from './Factory'\nimport { FileViewFinder } from './FileViewFinder'\n\n/** Binds the ViewFactory (resources/views by default) and merges the `view` config, like Laravel's config/view.php. */\nexport class ViewServiceProvider extends ServiceProvider {\n override register(): void {\n this.mergeConfigFrom({ paths: [this.app.resourcePath('views')] }, 'view')\n this.app.singleton(ViewFactory, () => {\n const paths = this.app.make(ConfigRepository).get<string[]>('view.paths', [this.app.resourcePath('views')])\n return new Factory(new FileViewFinder(paths))\n })\n }\n}\n"],"mappings":";;;;;;;;;;AAEA,IAAM,UAAkC,EAAE,KAAK,SAAS,KAAK,QAAQ,KAAK,QAAQ,KAAK,UAAU,KAAK,SAAS;AAC/G,IAAM,SAAS;AAGR,IAAM,aAAN,MAAqC;AAAA,EAC1C,YAA6B,OAAe,IAAI;AAAnB;AAAA,EAAoB;AAAA,EAApB;AAAA,EAE7B,SAAiB;AACf,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,WAAmB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Factory","ViewFactory","ViewFactory"]}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Htmlable } from '@orieljs/contracts';
|
|
2
|
+
|
|
3
|
+
type ClassValue = string | number | null | undefined | false | ClassValue[] | Record<string, unknown>;
|
|
4
|
+
type StyleObject = Record<string, string | number | null | undefined | false>;
|
|
5
|
+
|
|
6
|
+
/** Marks the objects jsx() returns (Symbol.for, so two copies of the package agree). */
|
|
7
|
+
declare const ELEMENT: unique symbol;
|
|
8
|
+
type Props = Record<string, unknown>;
|
|
9
|
+
/** Anything that can appear as a child: text is escaped, Htmlable is emitted as-is, promises are awaited. */
|
|
10
|
+
type Renderable = OrielElement | string | number | bigint | boolean | null | undefined | Htmlable | Promise<Renderable> | Iterable<Renderable>;
|
|
11
|
+
/** A function component. It may be async: the renderer awaits it. */
|
|
12
|
+
type Component<P = Props> = (props: P) => Renderable | Promise<Renderable>;
|
|
13
|
+
/**
|
|
14
|
+
* `<>…</>` and `<Fragment>`: renders its children only. A symbol at runtime; typed as a component so that
|
|
15
|
+
* `<Fragment>` type-checks as a JSX tag.
|
|
16
|
+
*/
|
|
17
|
+
declare const Fragment: (props: {
|
|
18
|
+
children?: Renderable;
|
|
19
|
+
}) => Renderable;
|
|
20
|
+
type ElementType = string | Component<never>;
|
|
21
|
+
/** What `<div />` evaluates to: an inert description, rendered later by renderToString()/renderToStream(). */
|
|
22
|
+
interface OrielElement {
|
|
23
|
+
readonly [ELEMENT]: true;
|
|
24
|
+
readonly type: ElementType;
|
|
25
|
+
readonly props: Props;
|
|
26
|
+
readonly key: string | number | undefined;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The automatic JSX runtime (`jsxImportSource: "@orieljs/view"`). jsx() only describes elements; rendering
|
|
31
|
+
* (escaping, async components) happens in renderToString()/renderToStream().
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
declare function jsx(type: ElementType, props: Props | null, key?: string | number): OrielElement;
|
|
35
|
+
/** Same as jsx(); the compiler uses it when there are several static children. */
|
|
36
|
+
declare const jsxs: typeof jsx;
|
|
37
|
+
/** Attributes every intrinsic element accepts. Unknown attributes (hx-*, x-*, o:click, …) are allowed. */
|
|
38
|
+
interface HtmlAttributes {
|
|
39
|
+
children?: Renderable;
|
|
40
|
+
class?: ClassValue;
|
|
41
|
+
className?: ClassValue;
|
|
42
|
+
style?: string | StyleObject;
|
|
43
|
+
dangerouslySetInnerHTML?: {
|
|
44
|
+
__html: string;
|
|
45
|
+
};
|
|
46
|
+
[attribute: string]: unknown;
|
|
47
|
+
}
|
|
48
|
+
declare namespace JSX {
|
|
49
|
+
type Element = OrielElement;
|
|
50
|
+
/** Lets components be async: `async function Posts() { … }` is a valid element type. */
|
|
51
|
+
type ElementType = string | Component<never>;
|
|
52
|
+
interface ElementChildrenAttribute {
|
|
53
|
+
children: unknown;
|
|
54
|
+
}
|
|
55
|
+
interface IntrinsicAttributes {
|
|
56
|
+
key?: string | number;
|
|
57
|
+
}
|
|
58
|
+
interface IntrinsicElements {
|
|
59
|
+
[element: string]: HtmlAttributes;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export { Fragment, type HtmlAttributes, JSX, jsx, jsxs };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@orieljs/view",
|
|
3
|
+
"version": "0.1.0-alpha.1",
|
|
4
|
+
"description": "The Oriel View component.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/orieljs/framework.git",
|
|
11
|
+
"directory": "src/Oriel/View"
|
|
12
|
+
},
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=22"
|
|
15
|
+
},
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./jsx-runtime": {
|
|
23
|
+
"types": "./dist/jsx-runtime.d.ts",
|
|
24
|
+
"import": "./dist/jsx-runtime.js"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"dist",
|
|
32
|
+
"LICENSE",
|
|
33
|
+
"NOTICE"
|
|
34
|
+
],
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@orieljs/container": "0.1.0-alpha.1",
|
|
37
|
+
"@orieljs/contracts": "0.1.0-alpha.1",
|
|
38
|
+
"@orieljs/support": "0.1.0-alpha.1"
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "tsup && node ../../../scripts/copy-license.mjs"
|
|
42
|
+
}
|
|
43
|
+
}
|