@viglet/shio-react-sdk 2026.2.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 +201 -0
- package/dist/client.d.ts +6 -0
- package/dist/components/shio-field.d.ts +24 -0
- package/dist/components/shio-image.d.ts +9 -0
- package/dist/components/shio-relator.d.ts +14 -0
- package/dist/components/shio-rich-text.d.ts +13 -0
- package/dist/hooks/use-async.d.ts +16 -0
- package/dist/hooks/use-shio-breadcrumb.d.ts +6 -0
- package/dist/hooks/use-shio-children.d.ts +3 -0
- package/dist/hooks/use-shio-post.d.ts +8 -0
- package/dist/hooks/use-shio-query.d.ts +3 -0
- package/dist/hooks/use-shio-sites.d.ts +5 -0
- package/dist/index.d.ts +19 -0
- package/dist/provider.d.ts +17 -0
- package/dist/shio-react-sdk.js +154 -0
- package/dist/shio-react-sdk.umd.cjs +1 -0
- package/dist/types.d.ts +6 -0
- package/package.json +46 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The HTTP client now lives in the framework-agnostic core package. This module
|
|
3
|
+
* re-exports it so existing `import { ShioClient } from "@viglet/shio-react-sdk"`
|
|
4
|
+
* keeps working — React is one consumer of the core, not a parallel client.
|
|
5
|
+
*/
|
|
6
|
+
export { ShioClient, createShioClient } from "@viglet/shio-client";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
export type ShioFieldKind = "text" | "html" | "image" | "list" | "json";
|
|
3
|
+
export interface ShioFieldProps {
|
|
4
|
+
/** A single value from a post's `attrs` map. */
|
|
5
|
+
value: unknown;
|
|
6
|
+
/**
|
|
7
|
+
* Force a renderer. When omitted, the kind is inferred from the value shape.
|
|
8
|
+
*
|
|
9
|
+
* NOTE: the CDA delivers `attrs` as a plain JSON map without per-field widget
|
|
10
|
+
* metadata, so inference is heuristic. For exact widget fidelity, pass `as`
|
|
11
|
+
* explicitly (full widget-map resolution awaits post-type schema exposure in
|
|
12
|
+
* the CDA — see roadmap SH11).
|
|
13
|
+
*/
|
|
14
|
+
as?: ShioFieldKind;
|
|
15
|
+
/** Prefix for relative image paths when `as="image"` is inferred/forced. */
|
|
16
|
+
baseUrl?: string;
|
|
17
|
+
className?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Renders a single post field, picking a renderer by the value's shape (or the
|
|
21
|
+
* explicit `as` prop). A small, dependency-free default — swap in your own
|
|
22
|
+
* renderers for richer field types.
|
|
23
|
+
*/
|
|
24
|
+
export declare function ShioField({ value, as, baseUrl, className }: ShioFieldProps): ReactNode;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ImgHTMLAttributes } from "react";
|
|
2
|
+
export interface ShioImageProps extends Omit<ImgHTMLAttributes<HTMLImageElement>, "src"> {
|
|
3
|
+
/** File field value — an absolute URL or a path relative to {@link baseUrl}. */
|
|
4
|
+
src: string | null | undefined;
|
|
5
|
+
/** Prefix for relative `src` values (e.g. the Shio instance URL). */
|
|
6
|
+
baseUrl?: string;
|
|
7
|
+
}
|
|
8
|
+
/** Renders a File/image field value, resolving relative paths against `baseUrl`. */
|
|
9
|
+
export declare function ShioImage({ src, baseUrl, alt, ...rest }: ShioImageProps): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
export interface ShioRelatorProps<T = Record<string, unknown>> {
|
|
3
|
+
/** Relator field value — expected to be an array of nested item objects. */
|
|
4
|
+
items: unknown;
|
|
5
|
+
/** Render prop for each item. */
|
|
6
|
+
children: (item: T, index: number) => ReactNode;
|
|
7
|
+
/** Optional key extractor (defaults to the array index). */
|
|
8
|
+
keyFor?: (item: T, index: number) => string | number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Renders a Relator field (a list of nested content items). Tolerant of a
|
|
12
|
+
* non-array value (renders nothing), since the CDA `attrs` payload is untyped.
|
|
13
|
+
*/
|
|
14
|
+
export declare function ShioRelator<T = Record<string, unknown>>({ items, children, keyFor, }: ShioRelatorProps<T>): import("react").JSX.Element;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { HTMLAttributes } from "react";
|
|
2
|
+
export interface ShioRichTextProps extends HTMLAttributes<HTMLDivElement> {
|
|
3
|
+
/** HTML string (e.g. an HTML Editor field value). */
|
|
4
|
+
html: string | null | undefined;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Renders an HTML field value.
|
|
8
|
+
*
|
|
9
|
+
* ⚠️ The HTML is injected verbatim via `dangerouslySetInnerHTML`. Shio content
|
|
10
|
+
* is authored by trusted editors, but if your content can contain untrusted
|
|
11
|
+
* input, sanitize upstream (e.g. with DOMPurify) before passing it here.
|
|
12
|
+
*/
|
|
13
|
+
export declare function ShioRichText({ html, ...rest }: ShioRichTextProps): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Result shape shared by all data hooks. */
|
|
2
|
+
export interface ShioAsyncState<T> {
|
|
3
|
+
data: T | undefined;
|
|
4
|
+
loading: boolean;
|
|
5
|
+
error: Error | null;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Internal helper that runs an abortable async fetch and tracks
|
|
9
|
+
* loading/data/error. Aborts the in-flight request on dependency change or
|
|
10
|
+
* unmount, and never sets state after an abort (no React warnings).
|
|
11
|
+
*
|
|
12
|
+
* @param fn receives an AbortSignal to forward to the client call
|
|
13
|
+
* @param deps re-run trigger (same contract as useEffect deps)
|
|
14
|
+
* @param enabled when false, the fetch is skipped and state resets to idle
|
|
15
|
+
*/
|
|
16
|
+
export declare function useAsync<T>(fn: (signal: AbortSignal) => Promise<T>, deps: unknown[], enabled?: boolean): ShioAsyncState<T>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ShioPath } from "@viglet/shio-client";
|
|
2
|
+
/**
|
|
3
|
+
* Get the breadcrumb path (site + root→current folder chain) for a folder or
|
|
4
|
+
* post. `null` when the object is unknown.
|
|
5
|
+
*/
|
|
6
|
+
export declare function useShioBreadcrumb(objectId: string | undefined): import("./use-async").ShioAsyncState<ShioPath | null>;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ShioListing, ShioPageParams } from "@viglet/shio-client";
|
|
2
|
+
/** List a folder's children (subfolders + published posts). `null` when the folder is unknown. */
|
|
3
|
+
export declare function useShioChildren(folderId: string | undefined, params?: ShioPageParams): import("./use-async").ShioAsyncState<ShioListing | null>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ShioPost } from "@viglet/shio-client";
|
|
2
|
+
/** Get a published post by id (attributes expanded). `null` when not found. */
|
|
3
|
+
export declare function useShioPost(postId: string | undefined): import("./use-async").ShioAsyncState<ShioPost | null>;
|
|
4
|
+
/**
|
|
5
|
+
* Resolve a published post by site + friendly URL — the client-side analog of
|
|
6
|
+
* the catch-all route. `null` when unresolved.
|
|
7
|
+
*/
|
|
8
|
+
export declare function useShioPostByUrl(siteId: string | undefined, url: string | undefined): import("./use-async").ShioAsyncState<ShioPost | null>;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ShioListing, ShioQueryParams } from "@viglet/shio-client";
|
|
2
|
+
/** Query published posts by site / folder / post type (always returns a listing). */
|
|
3
|
+
export declare function useShioQuery(params?: ShioQueryParams): import("./use-async").ShioAsyncState<ShioListing>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ShioSite } from "@viglet/shio-client";
|
|
2
|
+
/** List all published sites. */
|
|
3
|
+
export declare function useShioSites(): import("./use-async").ShioAsyncState<ShioSite[]>;
|
|
4
|
+
/** Get one site (with its root folder id) by id. */
|
|
5
|
+
export declare function useShioSite(siteId: string | undefined): import("./use-async").ShioAsyncState<ShioSite | null>;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export { ShioProvider, useShioClient } from "./provider";
|
|
2
|
+
export type { ShioProviderProps } from "./provider";
|
|
3
|
+
export { ShioClient, createShioClient } from "@viglet/shio-client";
|
|
4
|
+
export { ShioHttpError } from "@viglet/shio-client";
|
|
5
|
+
export type { ShioAsyncState } from "./hooks/use-async";
|
|
6
|
+
export { useShioSites, useShioSite } from "./hooks/use-shio-sites";
|
|
7
|
+
export { useShioChildren } from "./hooks/use-shio-children";
|
|
8
|
+
export { useShioBreadcrumb } from "./hooks/use-shio-breadcrumb";
|
|
9
|
+
export { useShioPost, useShioPostByUrl } from "./hooks/use-shio-post";
|
|
10
|
+
export { useShioQuery } from "./hooks/use-shio-query";
|
|
11
|
+
export { ShioRichText } from "./components/shio-rich-text";
|
|
12
|
+
export type { ShioRichTextProps } from "./components/shio-rich-text";
|
|
13
|
+
export { ShioImage } from "./components/shio-image";
|
|
14
|
+
export type { ShioImageProps } from "./components/shio-image";
|
|
15
|
+
export { ShioRelator } from "./components/shio-relator";
|
|
16
|
+
export type { ShioRelatorProps } from "./components/shio-relator";
|
|
17
|
+
export { ShioField } from "./components/shio-field";
|
|
18
|
+
export type { ShioFieldProps, ShioFieldKind } from "./components/shio-field";
|
|
19
|
+
export type { ShioClientConfig, ShioRequestOptions, ShioSite, ShioFolder, ShioPostSummary, ShioPost, ShioListing, ShioPath, ShioQueryParams, ShioPageParams, } from "@viglet/shio-client";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import { ShioClient } from "@viglet/shio-client";
|
|
3
|
+
import type { ShioClientConfig } from "@viglet/shio-client";
|
|
4
|
+
export type ShioProviderProps = {
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
} & (ShioClientConfig | {
|
|
7
|
+
client: ShioClient;
|
|
8
|
+
});
|
|
9
|
+
/**
|
|
10
|
+
* Provides a {@link ShioClient} (from `@viglet/shio-client`) to all child
|
|
11
|
+
* components. Either pass connection config (`baseUrl`, `apiToken`, ...) and the
|
|
12
|
+
* provider builds the client, or pass a pre-built `client` (useful for sharing
|
|
13
|
+
* one instance between SSR and the browser).
|
|
14
|
+
*/
|
|
15
|
+
export declare function ShioProvider(props: ShioProviderProps): import("react").JSX.Element;
|
|
16
|
+
/** Access the Shio client from context. */
|
|
17
|
+
export declare function useShioClient(): ShioClient;
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { jsx as u, Fragment as s } from "react/jsx-runtime";
|
|
2
|
+
import { createContext as S, useMemo as d, useContext as g, useState as y, useEffect as C, Fragment as A } from "react";
|
|
3
|
+
import { ShioClient as b } from "@viglet/shio-client";
|
|
4
|
+
import { ShioClient as q, ShioHttpError as G, createShioClient as Q } from "@viglet/shio-client";
|
|
5
|
+
const f = S(null);
|
|
6
|
+
function R(t) {
|
|
7
|
+
const { children: n } = t, i = "client" in t ? t.client : void 0, e = i ? void 0 : t, o = d(
|
|
8
|
+
() => i ?? new b(e),
|
|
9
|
+
// Rebuild only when a meaningful connection field changes.
|
|
10
|
+
[i, e == null ? void 0 : e.baseUrl, e == null ? void 0 : e.apiToken, e == null ? void 0 : e.fetch, e == null ? void 0 : e.credentials]
|
|
11
|
+
);
|
|
12
|
+
return /* @__PURE__ */ u(f.Provider, { value: o, children: n });
|
|
13
|
+
}
|
|
14
|
+
function c() {
|
|
15
|
+
const t = g(f);
|
|
16
|
+
if (!t)
|
|
17
|
+
throw new Error("useShioClient must be used within a <ShioProvider>");
|
|
18
|
+
return t;
|
|
19
|
+
}
|
|
20
|
+
function h(t, n, i = !0) {
|
|
21
|
+
const [e, o] = y({
|
|
22
|
+
data: void 0,
|
|
23
|
+
loading: i,
|
|
24
|
+
error: null
|
|
25
|
+
});
|
|
26
|
+
return C(() => {
|
|
27
|
+
if (!i) {
|
|
28
|
+
o({ data: void 0, loading: !1, error: null });
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const r = new AbortController();
|
|
32
|
+
return o((l) => ({ ...l, loading: !0, error: null })), t(r.signal).then((l) => {
|
|
33
|
+
r.signal.aborted || o({ data: l, loading: !1, error: null });
|
|
34
|
+
}).catch((l) => {
|
|
35
|
+
r.signal.aborted || o({
|
|
36
|
+
data: void 0,
|
|
37
|
+
loading: !1,
|
|
38
|
+
error: l instanceof Error ? l : new Error(String(l))
|
|
39
|
+
});
|
|
40
|
+
}), () => r.abort();
|
|
41
|
+
}, n), e;
|
|
42
|
+
}
|
|
43
|
+
function _() {
|
|
44
|
+
const t = c();
|
|
45
|
+
return h((n) => t.getSites({ signal: n }), [t]);
|
|
46
|
+
}
|
|
47
|
+
function z(t) {
|
|
48
|
+
const n = c();
|
|
49
|
+
return h(
|
|
50
|
+
(i) => n.getSite(t, { signal: i }),
|
|
51
|
+
[n, t],
|
|
52
|
+
!!t
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
function B(t, n) {
|
|
56
|
+
const i = c();
|
|
57
|
+
return h(
|
|
58
|
+
(e) => i.listChildren(t, n, { signal: e }),
|
|
59
|
+
[i, t, n == null ? void 0 : n.page, n == null ? void 0 : n.size],
|
|
60
|
+
!!t
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
function F(t) {
|
|
64
|
+
const n = c();
|
|
65
|
+
return h(
|
|
66
|
+
(i) => n.getPath(t, { signal: i }),
|
|
67
|
+
[n, t],
|
|
68
|
+
!!t
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
function H(t) {
|
|
72
|
+
const n = c();
|
|
73
|
+
return h(
|
|
74
|
+
(i) => n.getPost(t, { signal: i }),
|
|
75
|
+
[n, t],
|
|
76
|
+
!!t
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
function k(t, n) {
|
|
80
|
+
const i = c();
|
|
81
|
+
return h(
|
|
82
|
+
(e) => i.getPostByUrl(t, n, { signal: e }),
|
|
83
|
+
[i, t, n],
|
|
84
|
+
!!t && !!n
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
function v(t) {
|
|
88
|
+
const n = c();
|
|
89
|
+
return h(
|
|
90
|
+
(i) => n.query(t, { signal: i }),
|
|
91
|
+
[
|
|
92
|
+
n,
|
|
93
|
+
t == null ? void 0 : t.siteId,
|
|
94
|
+
t == null ? void 0 : t.folderId,
|
|
95
|
+
t == null ? void 0 : t.postType,
|
|
96
|
+
t == null ? void 0 : t.page,
|
|
97
|
+
t == null ? void 0 : t.size
|
|
98
|
+
]
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
function w({ html: t, ...n }) {
|
|
102
|
+
return t ? /* @__PURE__ */ u("div", { ...n, dangerouslySetInnerHTML: { __html: t } }) : null;
|
|
103
|
+
}
|
|
104
|
+
function x({ src: t, baseUrl: n, alt: i = "", ...e }) {
|
|
105
|
+
if (!t) return null;
|
|
106
|
+
const r = /^(https?:)?\/\//.test(t) || t.startsWith("data:") || !n ? t : `${n.replace(/\/+$/, "")}/${t.replace(/^\/+/, "")}`;
|
|
107
|
+
return /* @__PURE__ */ u("img", { src: r, alt: i, ...e });
|
|
108
|
+
}
|
|
109
|
+
function J({
|
|
110
|
+
items: t,
|
|
111
|
+
children: n,
|
|
112
|
+
keyFor: i
|
|
113
|
+
}) {
|
|
114
|
+
const e = Array.isArray(t) ? t : [];
|
|
115
|
+
return /* @__PURE__ */ u(s, { children: e.map((o, r) => /* @__PURE__ */ u(A, { children: n(o, r) }, i ? i(o, r) : r)) });
|
|
116
|
+
}
|
|
117
|
+
const E = /<[a-z][\s\S]*>/i, P = /\.(png|jpe?g|gif|webp|svg|avif)$/i;
|
|
118
|
+
function T(t) {
|
|
119
|
+
return typeof t == "string" ? E.test(t) ? "html" : P.test(t.trim()) ? "image" : "text" : Array.isArray(t) ? "list" : t !== null && typeof t == "object" ? "json" : "text";
|
|
120
|
+
}
|
|
121
|
+
function L({ value: t, as: n, baseUrl: i, className: e }) {
|
|
122
|
+
if (t == null || t === "") return null;
|
|
123
|
+
switch (n ?? T(t)) {
|
|
124
|
+
case "html":
|
|
125
|
+
return /* @__PURE__ */ u(w, { className: e, html: String(t) });
|
|
126
|
+
case "image":
|
|
127
|
+
return /* @__PURE__ */ u(x, { className: e, src: String(t), baseUrl: i });
|
|
128
|
+
case "list":
|
|
129
|
+
return /* @__PURE__ */ u("ul", { className: e, children: t.map((r, l) => /* @__PURE__ */ u("li", { children: typeof r == "object" ? JSON.stringify(r) : String(r) }, l)) });
|
|
130
|
+
case "json":
|
|
131
|
+
return /* @__PURE__ */ u("pre", { className: e, children: JSON.stringify(t, null, 2) });
|
|
132
|
+
case "text":
|
|
133
|
+
default:
|
|
134
|
+
return /* @__PURE__ */ u("span", { className: e, children: String(t) });
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
export {
|
|
138
|
+
q as ShioClient,
|
|
139
|
+
L as ShioField,
|
|
140
|
+
G as ShioHttpError,
|
|
141
|
+
x as ShioImage,
|
|
142
|
+
R as ShioProvider,
|
|
143
|
+
J as ShioRelator,
|
|
144
|
+
w as ShioRichText,
|
|
145
|
+
Q as createShioClient,
|
|
146
|
+
F as useShioBreadcrumb,
|
|
147
|
+
B as useShioChildren,
|
|
148
|
+
c as useShioClient,
|
|
149
|
+
H as useShioPost,
|
|
150
|
+
k as useShioPostByUrl,
|
|
151
|
+
v as useShioQuery,
|
|
152
|
+
z as useShioSite,
|
|
153
|
+
_ as useShioSites
|
|
154
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(r,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("react/jsx-runtime"),require("react"),require("@viglet/shio-client")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","@viglet/shio-client"],o):(r=typeof globalThis<"u"?globalThis:r||self,o(r.ShioReactSdk={},r.jsxRuntime,r.React,r.ShioClient))})(this,(function(r,o,f,d){"use strict";const s=f.createContext(null);function b(e){const{children:t}=e,i="client"in e?e.client:void 0,n=i?void 0:e,c=f.useMemo(()=>i??new d.ShioClient(n),[i,n==null?void 0:n.baseUrl,n==null?void 0:n.apiToken,n==null?void 0:n.fetch,n==null?void 0:n.credentials]);return o.jsx(s.Provider,{value:c,children:t})}function h(){const e=f.useContext(s);if(!e)throw new Error("useShioClient must be used within a <ShioProvider>");return e}function S(e,t,i=!0){const[n,c]=f.useState({data:void 0,loading:i,error:null});return f.useEffect(()=>{if(!i){c({data:void 0,loading:!1,error:null});return}const u=new AbortController;return c(l=>({...l,loading:!0,error:null})),e(u.signal).then(l=>{u.signal.aborted||c({data:l,loading:!1,error:null})}).catch(l=>{u.signal.aborted||c({data:void 0,loading:!1,error:l instanceof Error?l:new Error(String(l))})}),()=>u.abort()},t),n}function P(){const e=h();return S(t=>e.getSites({signal:t}),[e])}function C(e){const t=h();return S(i=>t.getSite(e,{signal:i}),[t,e],!!e)}function j(e,t){const i=h();return S(n=>i.listChildren(e,t,{signal:n}),[i,e,t==null?void 0:t.page,t==null?void 0:t.size],!!e)}function A(e){const t=h();return S(i=>t.getPath(e,{signal:i}),[t,e],!!e)}function E(e){const t=h();return S(i=>t.getPost(e,{signal:i}),[t,e],!!e)}function T(e,t){const i=h();return S(n=>i.getPostByUrl(e,t,{signal:n}),[i,e,t],!!e&&!!t)}function w(e){const t=h();return S(i=>t.query(e,{signal:i}),[t,e==null?void 0:e.siteId,e==null?void 0:e.folderId,e==null?void 0:e.postType,e==null?void 0:e.page,e==null?void 0:e.size])}function g({html:e,...t}){return e?o.jsx("div",{...t,dangerouslySetInnerHTML:{__html:e}}):null}function y({src:e,baseUrl:t,alt:i="",...n}){if(!e)return null;const u=/^(https?:)?\/\//.test(e)||e.startsWith("data:")||!t?e:`${t.replace(/\/+$/,"")}/${e.replace(/^\/+/,"")}`;return o.jsx("img",{src:u,alt:i,...n})}function v({items:e,children:t,keyFor:i}){const n=Array.isArray(e)?e:[];return o.jsx(o.Fragment,{children:n.map((c,u)=>o.jsx(f.Fragment,{children:t(c,u)},i?i(c,u):u))})}const O=/<[a-z][\s\S]*>/i,B=/\.(png|jpe?g|gif|webp|svg|avif)$/i;function M(e){return typeof e=="string"?O.test(e)?"html":B.test(e.trim())?"image":"text":Array.isArray(e)?"list":e!==null&&typeof e=="object"?"json":"text"}function q({value:e,as:t,baseUrl:i,className:n}){if(e==null||e==="")return null;switch(t??M(e)){case"html":return o.jsx(g,{className:n,html:String(e)});case"image":return o.jsx(y,{className:n,src:String(e),baseUrl:i});case"list":return o.jsx("ul",{className:n,children:e.map((u,l)=>o.jsx("li",{children:typeof u=="object"?JSON.stringify(u):String(u)},l))});case"json":return o.jsx("pre",{className:n,children:JSON.stringify(e,null,2)});case"text":default:return o.jsx("span",{className:n,children:String(e)})}}Object.defineProperty(r,"ShioClient",{enumerable:!0,get:()=>d.ShioClient}),Object.defineProperty(r,"ShioHttpError",{enumerable:!0,get:()=>d.ShioHttpError}),Object.defineProperty(r,"createShioClient",{enumerable:!0,get:()=>d.createShioClient}),r.ShioField=q,r.ShioImage=y,r.ShioProvider=b,r.ShioRelator=v,r.ShioRichText=g,r.useShioBreadcrumb=A,r.useShioChildren=j,r.useShioClient=h,r.useShioPost=E,r.useShioPostByUrl=T,r.useShioQuery=w,r.useShioSite=C,r.useShioSites=P,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})}));
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The content types are defined once in the framework-agnostic core and
|
|
3
|
+
* re-exported here for convenience, so React consumers can import them from a
|
|
4
|
+
* single package.
|
|
5
|
+
*/
|
|
6
|
+
export type { ShioClientConfig, ShioRequestOptions, ShioSite, ShioFolder, ShioPostSummary, ShioPost, ShioListing, ShioPath, ShioQueryParams, ShioPageParams, } from "@viglet/shio-client";
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@viglet/shio-react-sdk",
|
|
3
|
+
"version": "2026.2.1",
|
|
4
|
+
"description": "React SDK for consuming Shio CMS content via the Content Delivery API (CDA). Hooks + render components built on @viglet/shio-client.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/shio-react-sdk.umd.cjs",
|
|
7
|
+
"module": "dist/shio-react-sdk.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/shio-react-sdk.js",
|
|
13
|
+
"require": "./dist/shio-react-sdk.umd.cjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@viglet/shio-client": "2026.2.1"
|
|
21
|
+
},
|
|
22
|
+
"peerDependencies": {
|
|
23
|
+
"react": ">=18.0.0"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@types/react": "^19.1.2",
|
|
27
|
+
"react": "^19.1.0",
|
|
28
|
+
"typescript": "^5.8.3",
|
|
29
|
+
"vite": "^6.3.1"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"shio",
|
|
33
|
+
"cms",
|
|
34
|
+
"headless",
|
|
35
|
+
"react",
|
|
36
|
+
"sdk",
|
|
37
|
+
"cda"
|
|
38
|
+
],
|
|
39
|
+
"author": "Viglet Team",
|
|
40
|
+
"license": "GPL-3.0",
|
|
41
|
+
"scripts": {
|
|
42
|
+
"dev": "vite build --watch",
|
|
43
|
+
"build": "vite build && tsc --emitDeclarationOnly",
|
|
44
|
+
"typecheck": "tsc --noEmit"
|
|
45
|
+
}
|
|
46
|
+
}
|