@palettelab/sdk 0.1.15 → 0.1.17
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/README.md +36 -0
- package/dist/components/index.d.mts +1 -1
- package/dist/components/index.d.ts +1 -1
- package/dist/hooks/index.d.mts +2 -2
- package/dist/hooks/index.d.ts +2 -2
- package/dist/{index-BDVWt7DE.d.ts → index-D0i35Hem.d.ts} +1 -1
- package/dist/{index-Bu5EQGYo.d.mts → index-DsfTFnZb.d.mts} +1 -1
- package/dist/index.d.mts +36 -4
- package/dist/index.d.ts +36 -4
- package/dist/index.js +291 -27
- package/dist/index.mjs +288 -26
- package/dist/{plugin-UV46q1mU.d.mts → plugin-dpLzOtF6.d.mts} +47 -2
- package/dist/{plugin-UV46q1mU.d.ts → plugin-dpLzOtF6.d.ts} +47 -2
- package/dist/router/index.d.mts +346 -0
- package/dist/router/index.d.ts +346 -0
- package/dist/router/index.js +247 -0
- package/dist/router/index.mjs +225 -0
- package/dist/types/index.d.mts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/package.json +6 -1
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { MouseEvent, ReactNode, AnchorHTMLAttributes, ComponentType } from 'react';
|
|
3
|
+
|
|
4
|
+
type Segment = {
|
|
5
|
+
kind: "static";
|
|
6
|
+
value: string;
|
|
7
|
+
} | {
|
|
8
|
+
kind: "dynamic";
|
|
9
|
+
name: string;
|
|
10
|
+
} | {
|
|
11
|
+
kind: "catchAll";
|
|
12
|
+
name: string;
|
|
13
|
+
optional?: boolean;
|
|
14
|
+
};
|
|
15
|
+
type PaletteAppRoute = {
|
|
16
|
+
id: string;
|
|
17
|
+
segments: Segment[];
|
|
18
|
+
score?: number;
|
|
19
|
+
page: ComponentType<Record<string, unknown>>;
|
|
20
|
+
layouts?: ComponentType<{
|
|
21
|
+
children: ReactNode;
|
|
22
|
+
}>[];
|
|
23
|
+
loading?: ComponentType<Record<string, unknown>>;
|
|
24
|
+
error?: ComponentType<{
|
|
25
|
+
error: Error;
|
|
26
|
+
reset: () => void;
|
|
27
|
+
}>;
|
|
28
|
+
notFound?: ComponentType<Record<string, unknown>>;
|
|
29
|
+
};
|
|
30
|
+
type RouterState = {
|
|
31
|
+
pathname: string;
|
|
32
|
+
searchParams: URLSearchParams;
|
|
33
|
+
params: Record<string, string | string[]>;
|
|
34
|
+
push: (path: string) => void;
|
|
35
|
+
replace: (path: string) => void;
|
|
36
|
+
};
|
|
37
|
+
declare function notFound(): never;
|
|
38
|
+
declare function PaletteAppRouter({ routes, notFound: NotFound, }: {
|
|
39
|
+
routes: PaletteAppRoute[];
|
|
40
|
+
notFound?: ComponentType<Record<string, unknown>>;
|
|
41
|
+
}): react.FunctionComponentElement<react.ProviderProps<RouterState | null>>;
|
|
42
|
+
declare function useRouter(): {
|
|
43
|
+
push: (path: string) => void;
|
|
44
|
+
replace: (path: string) => void;
|
|
45
|
+
back: () => void;
|
|
46
|
+
forward: () => void;
|
|
47
|
+
};
|
|
48
|
+
declare function usePathname(): string;
|
|
49
|
+
declare function useSearchParams(): URLSearchParams;
|
|
50
|
+
declare function useParams(): Record<string, string | string[]>;
|
|
51
|
+
declare function Link({ href, replace, onClick, children, ...props }: {
|
|
52
|
+
href: string;
|
|
53
|
+
replace?: boolean;
|
|
54
|
+
onClick?: (event: MouseEvent<HTMLAnchorElement>) => void;
|
|
55
|
+
children?: ReactNode;
|
|
56
|
+
} & Omit<AnchorHTMLAttributes<HTMLAnchorElement>, "href" | "onClick">): react.DetailedReactHTMLElement<{
|
|
57
|
+
href: string;
|
|
58
|
+
onClick: (event: MouseEvent<HTMLAnchorElement>) => void;
|
|
59
|
+
title?: string | undefined | undefined;
|
|
60
|
+
slot?: string | undefined | undefined;
|
|
61
|
+
style?: react.CSSProperties | undefined;
|
|
62
|
+
defaultValue?: string | number | readonly string[] | undefined;
|
|
63
|
+
type?: string | undefined | undefined;
|
|
64
|
+
download?: any;
|
|
65
|
+
hrefLang?: string | undefined | undefined;
|
|
66
|
+
media?: string | undefined | undefined;
|
|
67
|
+
ping?: string | undefined | undefined;
|
|
68
|
+
target?: react.HTMLAttributeAnchorTarget | undefined;
|
|
69
|
+
referrerPolicy?: react.HTMLAttributeReferrerPolicy | undefined;
|
|
70
|
+
defaultChecked?: boolean | undefined | undefined;
|
|
71
|
+
suppressContentEditableWarning?: boolean | undefined | undefined;
|
|
72
|
+
suppressHydrationWarning?: boolean | undefined | undefined;
|
|
73
|
+
accessKey?: string | undefined | undefined;
|
|
74
|
+
autoCapitalize?: "off" | "none" | "on" | "sentences" | "words" | "characters" | undefined | (string & {}) | undefined;
|
|
75
|
+
autoFocus?: boolean | undefined | undefined;
|
|
76
|
+
className?: string | undefined | undefined;
|
|
77
|
+
contentEditable?: (boolean | "true" | "false") | "inherit" | "plaintext-only" | undefined;
|
|
78
|
+
contextMenu?: string | undefined | undefined;
|
|
79
|
+
dir?: string | undefined | undefined;
|
|
80
|
+
draggable?: (boolean | "true" | "false") | undefined;
|
|
81
|
+
enterKeyHint?: "enter" | "done" | "go" | "next" | "previous" | "search" | "send" | undefined | undefined;
|
|
82
|
+
hidden?: boolean | undefined | undefined;
|
|
83
|
+
id?: string | undefined | undefined;
|
|
84
|
+
lang?: string | undefined | undefined;
|
|
85
|
+
nonce?: string | undefined | undefined;
|
|
86
|
+
spellCheck?: (boolean | "true" | "false") | undefined;
|
|
87
|
+
tabIndex?: number | undefined | undefined;
|
|
88
|
+
translate?: "yes" | "no" | undefined | undefined;
|
|
89
|
+
radioGroup?: string | undefined | undefined;
|
|
90
|
+
role?: react.AriaRole | undefined;
|
|
91
|
+
about?: string | undefined | undefined;
|
|
92
|
+
content?: string | undefined | undefined;
|
|
93
|
+
datatype?: string | undefined | undefined;
|
|
94
|
+
inlist?: any;
|
|
95
|
+
prefix?: string | undefined | undefined;
|
|
96
|
+
property?: string | undefined | undefined;
|
|
97
|
+
rel?: string | undefined | undefined;
|
|
98
|
+
resource?: string | undefined | undefined;
|
|
99
|
+
rev?: string | undefined | undefined;
|
|
100
|
+
typeof?: string | undefined | undefined;
|
|
101
|
+
vocab?: string | undefined | undefined;
|
|
102
|
+
autoCorrect?: string | undefined | undefined;
|
|
103
|
+
autoSave?: string | undefined | undefined;
|
|
104
|
+
color?: string | undefined | undefined;
|
|
105
|
+
itemProp?: string | undefined | undefined;
|
|
106
|
+
itemScope?: boolean | undefined | undefined;
|
|
107
|
+
itemType?: string | undefined | undefined;
|
|
108
|
+
itemID?: string | undefined | undefined;
|
|
109
|
+
itemRef?: string | undefined | undefined;
|
|
110
|
+
results?: number | undefined | undefined;
|
|
111
|
+
security?: string | undefined | undefined;
|
|
112
|
+
unselectable?: "on" | "off" | undefined | undefined;
|
|
113
|
+
popover?: "" | "auto" | "manual" | "hint" | undefined | undefined;
|
|
114
|
+
popoverTargetAction?: "toggle" | "show" | "hide" | undefined | undefined;
|
|
115
|
+
popoverTarget?: string | undefined | undefined;
|
|
116
|
+
inert?: boolean | undefined | undefined;
|
|
117
|
+
inputMode?: "none" | "text" | "tel" | "url" | "email" | "numeric" | "decimal" | "search" | undefined | undefined;
|
|
118
|
+
is?: string | undefined | undefined;
|
|
119
|
+
exportparts?: string | undefined | undefined;
|
|
120
|
+
part?: string | undefined | undefined;
|
|
121
|
+
"aria-activedescendant"?: string | undefined | undefined;
|
|
122
|
+
"aria-atomic"?: (boolean | "true" | "false") | undefined;
|
|
123
|
+
"aria-autocomplete"?: "none" | "inline" | "list" | "both" | undefined | undefined;
|
|
124
|
+
"aria-braillelabel"?: string | undefined | undefined;
|
|
125
|
+
"aria-brailleroledescription"?: string | undefined | undefined;
|
|
126
|
+
"aria-busy"?: (boolean | "true" | "false") | undefined;
|
|
127
|
+
"aria-checked"?: boolean | "false" | "mixed" | "true" | undefined | undefined;
|
|
128
|
+
"aria-colcount"?: number | undefined | undefined;
|
|
129
|
+
"aria-colindex"?: number | undefined | undefined;
|
|
130
|
+
"aria-colindextext"?: string | undefined | undefined;
|
|
131
|
+
"aria-colspan"?: number | undefined | undefined;
|
|
132
|
+
"aria-controls"?: string | undefined | undefined;
|
|
133
|
+
"aria-current"?: boolean | "false" | "true" | "page" | "step" | "location" | "date" | "time" | undefined | undefined;
|
|
134
|
+
"aria-describedby"?: string | undefined | undefined;
|
|
135
|
+
"aria-description"?: string | undefined | undefined;
|
|
136
|
+
"aria-details"?: string | undefined | undefined;
|
|
137
|
+
"aria-disabled"?: (boolean | "true" | "false") | undefined;
|
|
138
|
+
"aria-dropeffect"?: "none" | "copy" | "execute" | "link" | "move" | "popup" | undefined | undefined;
|
|
139
|
+
"aria-errormessage"?: string | undefined | undefined;
|
|
140
|
+
"aria-expanded"?: (boolean | "true" | "false") | undefined;
|
|
141
|
+
"aria-flowto"?: string | undefined | undefined;
|
|
142
|
+
"aria-grabbed"?: (boolean | "true" | "false") | undefined;
|
|
143
|
+
"aria-haspopup"?: boolean | "false" | "true" | "menu" | "listbox" | "tree" | "grid" | "dialog" | undefined | undefined;
|
|
144
|
+
"aria-hidden"?: (boolean | "true" | "false") | undefined;
|
|
145
|
+
"aria-invalid"?: boolean | "false" | "true" | "grammar" | "spelling" | undefined | undefined;
|
|
146
|
+
"aria-keyshortcuts"?: string | undefined | undefined;
|
|
147
|
+
"aria-label"?: string | undefined | undefined;
|
|
148
|
+
"aria-labelledby"?: string | undefined | undefined;
|
|
149
|
+
"aria-level"?: number | undefined | undefined;
|
|
150
|
+
"aria-live"?: "off" | "assertive" | "polite" | undefined | undefined;
|
|
151
|
+
"aria-modal"?: (boolean | "true" | "false") | undefined;
|
|
152
|
+
"aria-multiline"?: (boolean | "true" | "false") | undefined;
|
|
153
|
+
"aria-multiselectable"?: (boolean | "true" | "false") | undefined;
|
|
154
|
+
"aria-orientation"?: "horizontal" | "vertical" | undefined | undefined;
|
|
155
|
+
"aria-owns"?: string | undefined | undefined;
|
|
156
|
+
"aria-placeholder"?: string | undefined | undefined;
|
|
157
|
+
"aria-posinset"?: number | undefined | undefined;
|
|
158
|
+
"aria-pressed"?: boolean | "false" | "mixed" | "true" | undefined | undefined;
|
|
159
|
+
"aria-readonly"?: (boolean | "true" | "false") | undefined;
|
|
160
|
+
"aria-relevant"?: "additions" | "additions removals" | "additions text" | "all" | "removals" | "removals additions" | "removals text" | "text" | "text additions" | "text removals" | undefined | undefined;
|
|
161
|
+
"aria-required"?: (boolean | "true" | "false") | undefined;
|
|
162
|
+
"aria-roledescription"?: string | undefined | undefined;
|
|
163
|
+
"aria-rowcount"?: number | undefined | undefined;
|
|
164
|
+
"aria-rowindex"?: number | undefined | undefined;
|
|
165
|
+
"aria-rowindextext"?: string | undefined | undefined;
|
|
166
|
+
"aria-rowspan"?: number | undefined | undefined;
|
|
167
|
+
"aria-selected"?: (boolean | "true" | "false") | undefined;
|
|
168
|
+
"aria-setsize"?: number | undefined | undefined;
|
|
169
|
+
"aria-sort"?: "none" | "ascending" | "descending" | "other" | undefined | undefined;
|
|
170
|
+
"aria-valuemax"?: number | undefined | undefined;
|
|
171
|
+
"aria-valuemin"?: number | undefined | undefined;
|
|
172
|
+
"aria-valuenow"?: number | undefined | undefined;
|
|
173
|
+
"aria-valuetext"?: string | undefined | undefined;
|
|
174
|
+
dangerouslySetInnerHTML?: {
|
|
175
|
+
__html: string | TrustedHTML;
|
|
176
|
+
} | undefined | undefined;
|
|
177
|
+
onCopy?: react.ClipboardEventHandler<HTMLAnchorElement> | undefined;
|
|
178
|
+
onCopyCapture?: react.ClipboardEventHandler<HTMLAnchorElement> | undefined;
|
|
179
|
+
onCut?: react.ClipboardEventHandler<HTMLAnchorElement> | undefined;
|
|
180
|
+
onCutCapture?: react.ClipboardEventHandler<HTMLAnchorElement> | undefined;
|
|
181
|
+
onPaste?: react.ClipboardEventHandler<HTMLAnchorElement> | undefined;
|
|
182
|
+
onPasteCapture?: react.ClipboardEventHandler<HTMLAnchorElement> | undefined;
|
|
183
|
+
onCompositionEnd?: react.CompositionEventHandler<HTMLAnchorElement> | undefined;
|
|
184
|
+
onCompositionEndCapture?: react.CompositionEventHandler<HTMLAnchorElement> | undefined;
|
|
185
|
+
onCompositionStart?: react.CompositionEventHandler<HTMLAnchorElement> | undefined;
|
|
186
|
+
onCompositionStartCapture?: react.CompositionEventHandler<HTMLAnchorElement> | undefined;
|
|
187
|
+
onCompositionUpdate?: react.CompositionEventHandler<HTMLAnchorElement> | undefined;
|
|
188
|
+
onCompositionUpdateCapture?: react.CompositionEventHandler<HTMLAnchorElement> | undefined;
|
|
189
|
+
onFocus?: react.FocusEventHandler<HTMLAnchorElement> | undefined;
|
|
190
|
+
onFocusCapture?: react.FocusEventHandler<HTMLAnchorElement> | undefined;
|
|
191
|
+
onBlur?: react.FocusEventHandler<HTMLAnchorElement> | undefined;
|
|
192
|
+
onBlurCapture?: react.FocusEventHandler<HTMLAnchorElement> | undefined;
|
|
193
|
+
onChange?: react.ChangeEventHandler<HTMLAnchorElement, Element> | undefined;
|
|
194
|
+
onChangeCapture?: react.ChangeEventHandler<HTMLAnchorElement, Element> | undefined;
|
|
195
|
+
onBeforeInput?: react.InputEventHandler<HTMLAnchorElement> | undefined;
|
|
196
|
+
onBeforeInputCapture?: react.InputEventHandler<HTMLAnchorElement> | undefined;
|
|
197
|
+
onInput?: react.InputEventHandler<HTMLAnchorElement> | undefined;
|
|
198
|
+
onInputCapture?: react.InputEventHandler<HTMLAnchorElement> | undefined;
|
|
199
|
+
onReset?: react.ReactEventHandler<HTMLAnchorElement> | undefined;
|
|
200
|
+
onResetCapture?: react.ReactEventHandler<HTMLAnchorElement> | undefined;
|
|
201
|
+
onSubmit?: react.SubmitEventHandler<HTMLAnchorElement> | undefined;
|
|
202
|
+
onSubmitCapture?: react.SubmitEventHandler<HTMLAnchorElement> | undefined;
|
|
203
|
+
onInvalid?: react.ReactEventHandler<HTMLAnchorElement> | undefined;
|
|
204
|
+
onInvalidCapture?: react.ReactEventHandler<HTMLAnchorElement> | undefined;
|
|
205
|
+
onLoad?: react.ReactEventHandler<HTMLAnchorElement> | undefined;
|
|
206
|
+
onLoadCapture?: react.ReactEventHandler<HTMLAnchorElement> | undefined;
|
|
207
|
+
onError?: react.ReactEventHandler<HTMLAnchorElement> | undefined;
|
|
208
|
+
onErrorCapture?: react.ReactEventHandler<HTMLAnchorElement> | undefined;
|
|
209
|
+
onKeyDown?: react.KeyboardEventHandler<HTMLAnchorElement> | undefined;
|
|
210
|
+
onKeyDownCapture?: react.KeyboardEventHandler<HTMLAnchorElement> | undefined;
|
|
211
|
+
onKeyPress?: react.KeyboardEventHandler<HTMLAnchorElement> | undefined;
|
|
212
|
+
onKeyPressCapture?: react.KeyboardEventHandler<HTMLAnchorElement> | undefined;
|
|
213
|
+
onKeyUp?: react.KeyboardEventHandler<HTMLAnchorElement> | undefined;
|
|
214
|
+
onKeyUpCapture?: react.KeyboardEventHandler<HTMLAnchorElement> | undefined;
|
|
215
|
+
onAbort?: react.ReactEventHandler<HTMLAnchorElement> | undefined;
|
|
216
|
+
onAbortCapture?: react.ReactEventHandler<HTMLAnchorElement> | undefined;
|
|
217
|
+
onCanPlay?: react.ReactEventHandler<HTMLAnchorElement> | undefined;
|
|
218
|
+
onCanPlayCapture?: react.ReactEventHandler<HTMLAnchorElement> | undefined;
|
|
219
|
+
onCanPlayThrough?: react.ReactEventHandler<HTMLAnchorElement> | undefined;
|
|
220
|
+
onCanPlayThroughCapture?: react.ReactEventHandler<HTMLAnchorElement> | undefined;
|
|
221
|
+
onDurationChange?: react.ReactEventHandler<HTMLAnchorElement> | undefined;
|
|
222
|
+
onDurationChangeCapture?: react.ReactEventHandler<HTMLAnchorElement> | undefined;
|
|
223
|
+
onEmptied?: react.ReactEventHandler<HTMLAnchorElement> | undefined;
|
|
224
|
+
onEmptiedCapture?: react.ReactEventHandler<HTMLAnchorElement> | undefined;
|
|
225
|
+
onEncrypted?: react.ReactEventHandler<HTMLAnchorElement> | undefined;
|
|
226
|
+
onEncryptedCapture?: react.ReactEventHandler<HTMLAnchorElement> | undefined;
|
|
227
|
+
onEnded?: react.ReactEventHandler<HTMLAnchorElement> | undefined;
|
|
228
|
+
onEndedCapture?: react.ReactEventHandler<HTMLAnchorElement> | undefined;
|
|
229
|
+
onLoadedData?: react.ReactEventHandler<HTMLAnchorElement> | undefined;
|
|
230
|
+
onLoadedDataCapture?: react.ReactEventHandler<HTMLAnchorElement> | undefined;
|
|
231
|
+
onLoadedMetadata?: react.ReactEventHandler<HTMLAnchorElement> | undefined;
|
|
232
|
+
onLoadedMetadataCapture?: react.ReactEventHandler<HTMLAnchorElement> | undefined;
|
|
233
|
+
onLoadStart?: react.ReactEventHandler<HTMLAnchorElement> | undefined;
|
|
234
|
+
onLoadStartCapture?: react.ReactEventHandler<HTMLAnchorElement> | undefined;
|
|
235
|
+
onPause?: react.ReactEventHandler<HTMLAnchorElement> | undefined;
|
|
236
|
+
onPauseCapture?: react.ReactEventHandler<HTMLAnchorElement> | undefined;
|
|
237
|
+
onPlay?: react.ReactEventHandler<HTMLAnchorElement> | undefined;
|
|
238
|
+
onPlayCapture?: react.ReactEventHandler<HTMLAnchorElement> | undefined;
|
|
239
|
+
onPlaying?: react.ReactEventHandler<HTMLAnchorElement> | undefined;
|
|
240
|
+
onPlayingCapture?: react.ReactEventHandler<HTMLAnchorElement> | undefined;
|
|
241
|
+
onProgress?: react.ReactEventHandler<HTMLAnchorElement> | undefined;
|
|
242
|
+
onProgressCapture?: react.ReactEventHandler<HTMLAnchorElement> | undefined;
|
|
243
|
+
onRateChange?: react.ReactEventHandler<HTMLAnchorElement> | undefined;
|
|
244
|
+
onRateChangeCapture?: react.ReactEventHandler<HTMLAnchorElement> | undefined;
|
|
245
|
+
onSeeked?: react.ReactEventHandler<HTMLAnchorElement> | undefined;
|
|
246
|
+
onSeekedCapture?: react.ReactEventHandler<HTMLAnchorElement> | undefined;
|
|
247
|
+
onSeeking?: react.ReactEventHandler<HTMLAnchorElement> | undefined;
|
|
248
|
+
onSeekingCapture?: react.ReactEventHandler<HTMLAnchorElement> | undefined;
|
|
249
|
+
onStalled?: react.ReactEventHandler<HTMLAnchorElement> | undefined;
|
|
250
|
+
onStalledCapture?: react.ReactEventHandler<HTMLAnchorElement> | undefined;
|
|
251
|
+
onSuspend?: react.ReactEventHandler<HTMLAnchorElement> | undefined;
|
|
252
|
+
onSuspendCapture?: react.ReactEventHandler<HTMLAnchorElement> | undefined;
|
|
253
|
+
onTimeUpdate?: react.ReactEventHandler<HTMLAnchorElement> | undefined;
|
|
254
|
+
onTimeUpdateCapture?: react.ReactEventHandler<HTMLAnchorElement> | undefined;
|
|
255
|
+
onVolumeChange?: react.ReactEventHandler<HTMLAnchorElement> | undefined;
|
|
256
|
+
onVolumeChangeCapture?: react.ReactEventHandler<HTMLAnchorElement> | undefined;
|
|
257
|
+
onWaiting?: react.ReactEventHandler<HTMLAnchorElement> | undefined;
|
|
258
|
+
onWaitingCapture?: react.ReactEventHandler<HTMLAnchorElement> | undefined;
|
|
259
|
+
onAuxClick?: react.MouseEventHandler<HTMLAnchorElement> | undefined;
|
|
260
|
+
onAuxClickCapture?: react.MouseEventHandler<HTMLAnchorElement> | undefined;
|
|
261
|
+
onClickCapture?: react.MouseEventHandler<HTMLAnchorElement> | undefined;
|
|
262
|
+
onContextMenu?: react.MouseEventHandler<HTMLAnchorElement> | undefined;
|
|
263
|
+
onContextMenuCapture?: react.MouseEventHandler<HTMLAnchorElement> | undefined;
|
|
264
|
+
onDoubleClick?: react.MouseEventHandler<HTMLAnchorElement> | undefined;
|
|
265
|
+
onDoubleClickCapture?: react.MouseEventHandler<HTMLAnchorElement> | undefined;
|
|
266
|
+
onDrag?: react.DragEventHandler<HTMLAnchorElement> | undefined;
|
|
267
|
+
onDragCapture?: react.DragEventHandler<HTMLAnchorElement> | undefined;
|
|
268
|
+
onDragEnd?: react.DragEventHandler<HTMLAnchorElement> | undefined;
|
|
269
|
+
onDragEndCapture?: react.DragEventHandler<HTMLAnchorElement> | undefined;
|
|
270
|
+
onDragEnter?: react.DragEventHandler<HTMLAnchorElement> | undefined;
|
|
271
|
+
onDragEnterCapture?: react.DragEventHandler<HTMLAnchorElement> | undefined;
|
|
272
|
+
onDragExit?: react.DragEventHandler<HTMLAnchorElement> | undefined;
|
|
273
|
+
onDragExitCapture?: react.DragEventHandler<HTMLAnchorElement> | undefined;
|
|
274
|
+
onDragLeave?: react.DragEventHandler<HTMLAnchorElement> | undefined;
|
|
275
|
+
onDragLeaveCapture?: react.DragEventHandler<HTMLAnchorElement> | undefined;
|
|
276
|
+
onDragOver?: react.DragEventHandler<HTMLAnchorElement> | undefined;
|
|
277
|
+
onDragOverCapture?: react.DragEventHandler<HTMLAnchorElement> | undefined;
|
|
278
|
+
onDragStart?: react.DragEventHandler<HTMLAnchorElement> | undefined;
|
|
279
|
+
onDragStartCapture?: react.DragEventHandler<HTMLAnchorElement> | undefined;
|
|
280
|
+
onDrop?: react.DragEventHandler<HTMLAnchorElement> | undefined;
|
|
281
|
+
onDropCapture?: react.DragEventHandler<HTMLAnchorElement> | undefined;
|
|
282
|
+
onMouseDown?: react.MouseEventHandler<HTMLAnchorElement> | undefined;
|
|
283
|
+
onMouseDownCapture?: react.MouseEventHandler<HTMLAnchorElement> | undefined;
|
|
284
|
+
onMouseEnter?: react.MouseEventHandler<HTMLAnchorElement> | undefined;
|
|
285
|
+
onMouseLeave?: react.MouseEventHandler<HTMLAnchorElement> | undefined;
|
|
286
|
+
onMouseMove?: react.MouseEventHandler<HTMLAnchorElement> | undefined;
|
|
287
|
+
onMouseMoveCapture?: react.MouseEventHandler<HTMLAnchorElement> | undefined;
|
|
288
|
+
onMouseOut?: react.MouseEventHandler<HTMLAnchorElement> | undefined;
|
|
289
|
+
onMouseOutCapture?: react.MouseEventHandler<HTMLAnchorElement> | undefined;
|
|
290
|
+
onMouseOver?: react.MouseEventHandler<HTMLAnchorElement> | undefined;
|
|
291
|
+
onMouseOverCapture?: react.MouseEventHandler<HTMLAnchorElement> | undefined;
|
|
292
|
+
onMouseUp?: react.MouseEventHandler<HTMLAnchorElement> | undefined;
|
|
293
|
+
onMouseUpCapture?: react.MouseEventHandler<HTMLAnchorElement> | undefined;
|
|
294
|
+
onSelect?: react.ReactEventHandler<HTMLAnchorElement> | undefined;
|
|
295
|
+
onSelectCapture?: react.ReactEventHandler<HTMLAnchorElement> | undefined;
|
|
296
|
+
onTouchCancel?: react.TouchEventHandler<HTMLAnchorElement> | undefined;
|
|
297
|
+
onTouchCancelCapture?: react.TouchEventHandler<HTMLAnchorElement> | undefined;
|
|
298
|
+
onTouchEnd?: react.TouchEventHandler<HTMLAnchorElement> | undefined;
|
|
299
|
+
onTouchEndCapture?: react.TouchEventHandler<HTMLAnchorElement> | undefined;
|
|
300
|
+
onTouchMove?: react.TouchEventHandler<HTMLAnchorElement> | undefined;
|
|
301
|
+
onTouchMoveCapture?: react.TouchEventHandler<HTMLAnchorElement> | undefined;
|
|
302
|
+
onTouchStart?: react.TouchEventHandler<HTMLAnchorElement> | undefined;
|
|
303
|
+
onTouchStartCapture?: react.TouchEventHandler<HTMLAnchorElement> | undefined;
|
|
304
|
+
onPointerDown?: react.PointerEventHandler<HTMLAnchorElement> | undefined;
|
|
305
|
+
onPointerDownCapture?: react.PointerEventHandler<HTMLAnchorElement> | undefined;
|
|
306
|
+
onPointerMove?: react.PointerEventHandler<HTMLAnchorElement> | undefined;
|
|
307
|
+
onPointerMoveCapture?: react.PointerEventHandler<HTMLAnchorElement> | undefined;
|
|
308
|
+
onPointerUp?: react.PointerEventHandler<HTMLAnchorElement> | undefined;
|
|
309
|
+
onPointerUpCapture?: react.PointerEventHandler<HTMLAnchorElement> | undefined;
|
|
310
|
+
onPointerCancel?: react.PointerEventHandler<HTMLAnchorElement> | undefined;
|
|
311
|
+
onPointerCancelCapture?: react.PointerEventHandler<HTMLAnchorElement> | undefined;
|
|
312
|
+
onPointerEnter?: react.PointerEventHandler<HTMLAnchorElement> | undefined;
|
|
313
|
+
onPointerLeave?: react.PointerEventHandler<HTMLAnchorElement> | undefined;
|
|
314
|
+
onPointerOver?: react.PointerEventHandler<HTMLAnchorElement> | undefined;
|
|
315
|
+
onPointerOverCapture?: react.PointerEventHandler<HTMLAnchorElement> | undefined;
|
|
316
|
+
onPointerOut?: react.PointerEventHandler<HTMLAnchorElement> | undefined;
|
|
317
|
+
onPointerOutCapture?: react.PointerEventHandler<HTMLAnchorElement> | undefined;
|
|
318
|
+
onGotPointerCapture?: react.PointerEventHandler<HTMLAnchorElement> | undefined;
|
|
319
|
+
onGotPointerCaptureCapture?: react.PointerEventHandler<HTMLAnchorElement> | undefined;
|
|
320
|
+
onLostPointerCapture?: react.PointerEventHandler<HTMLAnchorElement> | undefined;
|
|
321
|
+
onLostPointerCaptureCapture?: react.PointerEventHandler<HTMLAnchorElement> | undefined;
|
|
322
|
+
onScroll?: react.UIEventHandler<HTMLAnchorElement> | undefined;
|
|
323
|
+
onScrollCapture?: react.UIEventHandler<HTMLAnchorElement> | undefined;
|
|
324
|
+
onScrollEnd?: react.UIEventHandler<HTMLAnchorElement> | undefined;
|
|
325
|
+
onScrollEndCapture?: react.UIEventHandler<HTMLAnchorElement> | undefined;
|
|
326
|
+
onWheel?: react.WheelEventHandler<HTMLAnchorElement> | undefined;
|
|
327
|
+
onWheelCapture?: react.WheelEventHandler<HTMLAnchorElement> | undefined;
|
|
328
|
+
onAnimationStart?: react.AnimationEventHandler<HTMLAnchorElement> | undefined;
|
|
329
|
+
onAnimationStartCapture?: react.AnimationEventHandler<HTMLAnchorElement> | undefined;
|
|
330
|
+
onAnimationEnd?: react.AnimationEventHandler<HTMLAnchorElement> | undefined;
|
|
331
|
+
onAnimationEndCapture?: react.AnimationEventHandler<HTMLAnchorElement> | undefined;
|
|
332
|
+
onAnimationIteration?: react.AnimationEventHandler<HTMLAnchorElement> | undefined;
|
|
333
|
+
onAnimationIterationCapture?: react.AnimationEventHandler<HTMLAnchorElement> | undefined;
|
|
334
|
+
onToggle?: react.ToggleEventHandler<HTMLAnchorElement> | undefined;
|
|
335
|
+
onBeforeToggle?: react.ToggleEventHandler<HTMLAnchorElement> | undefined;
|
|
336
|
+
onTransitionCancel?: react.TransitionEventHandler<HTMLAnchorElement> | undefined;
|
|
337
|
+
onTransitionCancelCapture?: react.TransitionEventHandler<HTMLAnchorElement> | undefined;
|
|
338
|
+
onTransitionEnd?: react.TransitionEventHandler<HTMLAnchorElement> | undefined;
|
|
339
|
+
onTransitionEndCapture?: react.TransitionEventHandler<HTMLAnchorElement> | undefined;
|
|
340
|
+
onTransitionRun?: react.TransitionEventHandler<HTMLAnchorElement> | undefined;
|
|
341
|
+
onTransitionRunCapture?: react.TransitionEventHandler<HTMLAnchorElement> | undefined;
|
|
342
|
+
onTransitionStart?: react.TransitionEventHandler<HTMLAnchorElement> | undefined;
|
|
343
|
+
onTransitionStartCapture?: react.TransitionEventHandler<HTMLAnchorElement> | undefined;
|
|
344
|
+
}, HTMLElement>;
|
|
345
|
+
|
|
346
|
+
export { Link, type PaletteAppRoute, PaletteAppRouter, notFound, useParams, usePathname, useRouter, useSearchParams };
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/router.tsx
|
|
21
|
+
var router_exports = {};
|
|
22
|
+
__export(router_exports, {
|
|
23
|
+
Link: () => Link,
|
|
24
|
+
PaletteAppRouter: () => PaletteAppRouter,
|
|
25
|
+
notFound: () => notFound,
|
|
26
|
+
useParams: () => useParams,
|
|
27
|
+
usePathname: () => usePathname,
|
|
28
|
+
useRouter: () => useRouter,
|
|
29
|
+
useSearchParams: () => useSearchParams
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(router_exports);
|
|
32
|
+
var import_react2 = require("react");
|
|
33
|
+
|
|
34
|
+
// src/hooks/use-platform.ts
|
|
35
|
+
var import_react = require("react");
|
|
36
|
+
var PlatformCtx = (0, import_react.createContext)(null);
|
|
37
|
+
function usePlatform() {
|
|
38
|
+
const ctx = (0, import_react.useContext)(PlatformCtx);
|
|
39
|
+
if (!ctx) {
|
|
40
|
+
throw new Error(
|
|
41
|
+
"usePlatform must be used within a PlatformProvider. This is provided automatically when your plugin runs on the Palette platform."
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
return ctx;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// src/router.tsx
|
|
48
|
+
var RouterCtx = (0, import_react2.createContext)(null);
|
|
49
|
+
var NOT_FOUND = /* @__PURE__ */ Symbol.for("palette.router.not-found");
|
|
50
|
+
function notFound() {
|
|
51
|
+
throw Object.assign(new Error("Palette route not found"), { code: NOT_FOUND });
|
|
52
|
+
}
|
|
53
|
+
function normalizePath(path) {
|
|
54
|
+
const clean = String(path || "/").split("#")[0].split("?")[0] || "/";
|
|
55
|
+
return `/${clean.replace(/^\/+/, "").replace(/\/+$/, "")}`.replace(/^\/$/, "/");
|
|
56
|
+
}
|
|
57
|
+
function splitPath(path) {
|
|
58
|
+
return normalizePath(path).split("/").filter(Boolean).map(decodeURIComponent);
|
|
59
|
+
}
|
|
60
|
+
function routeScore(route) {
|
|
61
|
+
if (typeof route.score === "number") return route.score;
|
|
62
|
+
return route.segments.reduce((score, segment) => {
|
|
63
|
+
if (segment.kind === "static") return score + 10;
|
|
64
|
+
if (segment.kind === "dynamic") return score + 5;
|
|
65
|
+
return score + (segment.optional ? 1 : 2);
|
|
66
|
+
}, route.segments.length);
|
|
67
|
+
}
|
|
68
|
+
function matchRoute(route, path) {
|
|
69
|
+
const parts = splitPath(path);
|
|
70
|
+
const params = {};
|
|
71
|
+
let index = 0;
|
|
72
|
+
for (const segment of route.segments) {
|
|
73
|
+
if (segment.kind === "catchAll") {
|
|
74
|
+
const rest = parts.slice(index);
|
|
75
|
+
if (!segment.optional && rest.length === 0) return null;
|
|
76
|
+
params[segment.name] = rest;
|
|
77
|
+
index = parts.length;
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
const value = parts[index];
|
|
81
|
+
if (value === void 0) return null;
|
|
82
|
+
if (segment.kind === "static") {
|
|
83
|
+
if (value !== segment.value) return null;
|
|
84
|
+
} else {
|
|
85
|
+
params[segment.name] = value;
|
|
86
|
+
}
|
|
87
|
+
index += 1;
|
|
88
|
+
}
|
|
89
|
+
return index === parts.length ? params : null;
|
|
90
|
+
}
|
|
91
|
+
function currentPluginPath(pluginId, routePath) {
|
|
92
|
+
if (routePath) return normalizePath(routePath);
|
|
93
|
+
if (typeof window === "undefined") return "/";
|
|
94
|
+
const path = window.location.pathname;
|
|
95
|
+
if (pluginId) {
|
|
96
|
+
const prefix = `/apps/${pluginId}`;
|
|
97
|
+
if (path === prefix) return "/";
|
|
98
|
+
if (path.startsWith(`${prefix}/`)) return normalizePath(path.slice(prefix.length));
|
|
99
|
+
}
|
|
100
|
+
return normalizePath(path);
|
|
101
|
+
}
|
|
102
|
+
function currentSearchParams() {
|
|
103
|
+
if (typeof window === "undefined") return new URLSearchParams();
|
|
104
|
+
return new URLSearchParams(window.location.search);
|
|
105
|
+
}
|
|
106
|
+
var PaletteRouteErrorBoundary = class extends import_react2.Component {
|
|
107
|
+
constructor() {
|
|
108
|
+
super(...arguments);
|
|
109
|
+
this.state = { error: null };
|
|
110
|
+
this.reset = () => this.setState({ error: null });
|
|
111
|
+
}
|
|
112
|
+
static getDerivedStateFromError(error) {
|
|
113
|
+
return { error };
|
|
114
|
+
}
|
|
115
|
+
componentDidCatch(_error, _info) {
|
|
116
|
+
}
|
|
117
|
+
render() {
|
|
118
|
+
const error = this.state.error;
|
|
119
|
+
if (!error) return this.props.children;
|
|
120
|
+
if (error.code === NOT_FOUND && this.props.notFound) {
|
|
121
|
+
return (0, import_react2.createElement)(this.props.notFound);
|
|
122
|
+
}
|
|
123
|
+
if (this.props.fallback) {
|
|
124
|
+
return (0, import_react2.createElement)(this.props.fallback, { error, reset: this.reset });
|
|
125
|
+
}
|
|
126
|
+
throw error;
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
function renderRoute(route) {
|
|
130
|
+
const page = (0, import_react2.createElement)(route.page);
|
|
131
|
+
const wrapped = (route.layouts || []).reduceRight(
|
|
132
|
+
(children, Layout) => (0, import_react2.createElement)(Layout, null, children),
|
|
133
|
+
page
|
|
134
|
+
);
|
|
135
|
+
return (0, import_react2.createElement)(
|
|
136
|
+
PaletteRouteErrorBoundary,
|
|
137
|
+
{ fallback: route.error, notFound: route.notFound },
|
|
138
|
+
wrapped
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
function PaletteAppRouter({
|
|
142
|
+
routes,
|
|
143
|
+
notFound: NotFound
|
|
144
|
+
}) {
|
|
145
|
+
const platform = usePlatform();
|
|
146
|
+
const [location, setLocation] = (0, import_react2.useState)(() => ({
|
|
147
|
+
pathname: currentPluginPath(platform.pluginId, platform.routePath),
|
|
148
|
+
searchParams: currentSearchParams()
|
|
149
|
+
}));
|
|
150
|
+
(0, import_react2.useEffect)(() => {
|
|
151
|
+
setLocation({
|
|
152
|
+
pathname: currentPluginPath(platform.pluginId, platform.routePath),
|
|
153
|
+
searchParams: currentSearchParams()
|
|
154
|
+
});
|
|
155
|
+
}, [platform.pluginId, platform.routePath]);
|
|
156
|
+
(0, import_react2.useEffect)(() => {
|
|
157
|
+
const sync = () => setLocation({
|
|
158
|
+
pathname: currentPluginPath(platform.pluginId, platform.routePath),
|
|
159
|
+
searchParams: currentSearchParams()
|
|
160
|
+
});
|
|
161
|
+
window.addEventListener("popstate", sync);
|
|
162
|
+
return () => window.removeEventListener("popstate", sync);
|
|
163
|
+
}, [platform.pluginId, platform.routePath]);
|
|
164
|
+
const sortedRoutes = (0, import_react2.useMemo)(
|
|
165
|
+
() => [...routes].sort((a, b) => routeScore(b) - routeScore(a)),
|
|
166
|
+
[routes]
|
|
167
|
+
);
|
|
168
|
+
const matched = (0, import_react2.useMemo)(() => {
|
|
169
|
+
for (const route of sortedRoutes) {
|
|
170
|
+
const params = matchRoute(route, location.pathname);
|
|
171
|
+
if (params) return { route, params };
|
|
172
|
+
}
|
|
173
|
+
return null;
|
|
174
|
+
}, [location.pathname, sortedRoutes]);
|
|
175
|
+
const navigate = (0, import_react2.useCallback)((target, replace = false) => {
|
|
176
|
+
const [pathPart, queryPart = ""] = String(target || "/").split("?");
|
|
177
|
+
const pathname = normalizePath(pathPart);
|
|
178
|
+
const next = `${pathname}${queryPart ? `?${queryPart}` : ""}`;
|
|
179
|
+
setLocation({ pathname, searchParams: new URLSearchParams(queryPart) });
|
|
180
|
+
const currentPath = typeof window === "undefined" ? "" : window.location.pathname;
|
|
181
|
+
const inPalettePath = platform.pluginId && (currentPath.startsWith(`/apps/${platform.pluginId}`) || platform.routePath !== void 0);
|
|
182
|
+
const osPath = inPalettePath && platform.pluginId ? `/apps/${platform.pluginId}${pathname === "/" ? "" : pathname}${queryPart ? `?${queryPart}` : ""}` : next;
|
|
183
|
+
if (replace && typeof window !== "undefined") window.history.replaceState(null, "", osPath);
|
|
184
|
+
else platform.navigate(osPath);
|
|
185
|
+
}, [platform]);
|
|
186
|
+
const state = (0, import_react2.useMemo)(() => ({
|
|
187
|
+
pathname: location.pathname,
|
|
188
|
+
searchParams: location.searchParams,
|
|
189
|
+
params: matched?.params || {},
|
|
190
|
+
push: (path) => navigate(path, false),
|
|
191
|
+
replace: (path) => navigate(path, true)
|
|
192
|
+
}), [location.pathname, location.searchParams, matched?.params, navigate]);
|
|
193
|
+
const content = matched ? renderRoute(matched.route) : NotFound ? (0, import_react2.createElement)(NotFound) : (0, import_react2.createElement)("div", null, "Page not found");
|
|
194
|
+
return (0, import_react2.createElement)(RouterCtx.Provider, { value: state }, content);
|
|
195
|
+
}
|
|
196
|
+
function useRouterState() {
|
|
197
|
+
const value = (0, import_react2.useContext)(RouterCtx);
|
|
198
|
+
if (!value) throw new Error("Palette app router hooks must be used inside PaletteAppRouter");
|
|
199
|
+
return value;
|
|
200
|
+
}
|
|
201
|
+
function useRouter() {
|
|
202
|
+
const { push, replace } = useRouterState();
|
|
203
|
+
return { push, replace, back: () => window.history.back(), forward: () => window.history.forward() };
|
|
204
|
+
}
|
|
205
|
+
function usePathname() {
|
|
206
|
+
return useRouterState().pathname;
|
|
207
|
+
}
|
|
208
|
+
function useSearchParams() {
|
|
209
|
+
return useRouterState().searchParams;
|
|
210
|
+
}
|
|
211
|
+
function useParams() {
|
|
212
|
+
return useRouterState().params;
|
|
213
|
+
}
|
|
214
|
+
function Link({
|
|
215
|
+
href,
|
|
216
|
+
replace,
|
|
217
|
+
onClick,
|
|
218
|
+
children,
|
|
219
|
+
...props
|
|
220
|
+
}) {
|
|
221
|
+
const router = useRouter();
|
|
222
|
+
return (0, import_react2.createElement)(
|
|
223
|
+
"a",
|
|
224
|
+
{
|
|
225
|
+
...props,
|
|
226
|
+
href,
|
|
227
|
+
onClick: (event) => {
|
|
228
|
+
onClick?.(event);
|
|
229
|
+
if (event.defaultPrevented || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
|
|
230
|
+
event.preventDefault();
|
|
231
|
+
if (replace) router.replace(href);
|
|
232
|
+
else router.push(href);
|
|
233
|
+
}
|
|
234
|
+
},
|
|
235
|
+
children
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
239
|
+
0 && (module.exports = {
|
|
240
|
+
Link,
|
|
241
|
+
PaletteAppRouter,
|
|
242
|
+
notFound,
|
|
243
|
+
useParams,
|
|
244
|
+
usePathname,
|
|
245
|
+
useRouter,
|
|
246
|
+
useSearchParams
|
|
247
|
+
});
|