@blocklet/pages-kit 0.2.310 → 0.2.312

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.
Files changed (29) hide show
  1. package/lib/cjs/builtin/async/ai-runtime/index.js +2 -0
  2. package/lib/cjs/builtin/async/ai-runtime/runtime/ChatBotButton/index.js +9 -9
  3. package/lib/cjs/builtin/async/ai-runtime/runtime-components/ChatOutput/MessageMetadataRenderer.js +8 -5
  4. package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/Input.js +152 -0
  5. package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/Output.js +79 -0
  6. package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/Page.js +147 -0
  7. package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/index.js +12 -0
  8. package/lib/cjs/builtin/mui/material.js +3 -2
  9. package/lib/cjs/tsconfig.tsbuildinfo +1 -0
  10. package/lib/cjs/utils/inject-global-components-dump-json.js +1167 -0
  11. package/lib/esm/builtin/async/ai-runtime/index.js +2 -0
  12. package/lib/esm/builtin/async/ai-runtime/runtime/ChatBotButton/index.js +10 -10
  13. package/lib/esm/builtin/async/ai-runtime/runtime-components/ChatOutput/MessageMetadataRenderer.js +8 -5
  14. package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/Input.js +146 -0
  15. package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/Output.js +73 -0
  16. package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/Page.js +142 -0
  17. package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/index.js +3 -0
  18. package/lib/esm/builtin/mui/material.js +1 -1
  19. package/lib/esm/tsconfig.tsbuildinfo +1 -0
  20. package/lib/esm/utils/inject-global-components-dump-json.js +1165 -0
  21. package/lib/types/builtin/async/ai-runtime/index.d.ts +1 -0
  22. package/lib/types/builtin/async/ai-runtime/runtime-components/V0/Input.d.ts +7 -0
  23. package/lib/types/builtin/async/ai-runtime/runtime-components/V0/Output.d.ts +1 -0
  24. package/lib/types/builtin/async/ai-runtime/runtime-components/V0/Page.d.ts +5 -0
  25. package/lib/types/builtin/async/ai-runtime/runtime-components/V0/index.d.ts +3 -0
  26. package/lib/types/builtin/mui/material.d.ts +1 -1
  27. package/lib/types/tsconfig.tsbuildinfo +1 -0
  28. package/lib/types/utils/inject-global-components-dump-json.d.ts +1 -0
  29. package/package.json +11 -7
@@ -0,0 +1,1167 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /* eslint-disable no-console */
4
+ const ufo_1 = require("ufo");
5
+ const dumpJSON = [
6
+ // '@blocklet/pages-kit/builtin/dayjs'
7
+ {
8
+ name: '@blocklet/pages-kit/builtin/dayjs',
9
+ description: 'A dayjs component for pages-kit builtin package',
10
+ docs: {
11
+ components: ['dayjs'],
12
+ import: "import dayjs from '@blocklet/pages-kit/builtin/dayjs'",
13
+ export: "import dayjs from 'dayjs'; export default dayjs;",
14
+ examples: [
15
+ {
16
+ source: 'format-time-demo.tsx',
17
+ code: `
18
+ import dayjs from '@blocklet/pages-kit/builtin/dayjs'
19
+
20
+ export default function DayjsDemo() {
21
+ return <div>{dayjs().format('YYYY-MM-DD HH:mm:ss')}</div>
22
+ }`,
23
+ },
24
+ {
25
+ source: 'get-relative-time-demo.tsx',
26
+ code: `
27
+ import dayjs from '@blocklet/pages-kit/builtin/dayjs'
28
+
29
+ export default function DayjsDemo() {
30
+ return <div>{dayjs().fromNow()}</div>
31
+ }
32
+ `,
33
+ },
34
+ ],
35
+ },
36
+ },
37
+ // '@blocklet/pages-kit/builtin/utils'
38
+ {
39
+ name: '@blocklet/pages-kit/builtin/utils',
40
+ description: 'A utils component for pages-kit builtin package',
41
+ docs: {
42
+ components: ['joinURL', 'withQuery', 'getQuery', 'getComponentMountPoint'],
43
+ import: "import * as utils from '@blocklet/pages-kit/builtin/utils'",
44
+ export: `
45
+ export { joinURL, withQuery, getQuery } from 'ufo';
46
+
47
+ export function getComponentMountPoint(name: string) {
48
+ if (typeof window === 'undefined') {
49
+ // eslint-disable-next-line global-require
50
+ return require('@blocklet/sdk/lib/component').getComponentMountPoint(name);
51
+ }
52
+ return globalThis.blocklet?.componentMountPoints.find((i) => i.name === name || i.did === name)?.mountPoint;
53
+ }
54
+ `,
55
+ examples: [
56
+ {
57
+ source: 'get-component-mount-point-demo.tsx',
58
+ code: `
59
+ import { getComponentMountPoint } from '@blocklet/pages-kit/builtin/utils';
60
+
61
+ const componentMountPoint = getComponentMountPoint('pages-kit');
62
+ `,
63
+ },
64
+ {
65
+ source: 'join-url-demo.tsx',
66
+ code: `
67
+ import { joinURL } from '@blocklet/pages-kit/builtin/utils';
68
+
69
+ const newUrl = joinURL('https://example.com', '/path');
70
+ `,
71
+ },
72
+ ],
73
+ },
74
+ },
75
+ // '@blocklet/pages-kit/builtin/react'
76
+ {
77
+ name: '@blocklet/pages-kit/builtin/react',
78
+ description: 'A React component for pages-kit builtin package, export React and all React hooks',
79
+ docs: {
80
+ components: [
81
+ 'Children',
82
+ 'Component',
83
+ 'Fragment',
84
+ 'Profiler',
85
+ 'PureComponent',
86
+ 'StrictMode',
87
+ 'Suspense',
88
+ 'cloneElement',
89
+ 'createContext',
90
+ 'createElement',
91
+ 'createFactory',
92
+ 'createRef',
93
+ 'forwardRef',
94
+ 'isValidElement',
95
+ 'lazy',
96
+ 'memo',
97
+ 'startTransition',
98
+ 'useCallback',
99
+ 'useContext',
100
+ 'useDebugValue',
101
+ 'useDeferredValue',
102
+ 'useEffect',
103
+ 'useId',
104
+ 'useImperativeHandle',
105
+ 'useInsertionEffect',
106
+ 'useLayoutEffect',
107
+ 'useMemo',
108
+ 'useReducer',
109
+ 'useRef',
110
+ 'useState',
111
+ 'useSyncExternalStore',
112
+ 'useTransition',
113
+ 'version',
114
+ ],
115
+ import: "import React from '@blocklet/pages-kit/builtin/react'",
116
+ export: `
117
+ import * as React from 'react';
118
+
119
+ export default React;
120
+
121
+ export {
122
+ Children,
123
+ Component,
124
+ Fragment,
125
+ Profiler,
126
+ PureComponent,
127
+ StrictMode,
128
+ Suspense,
129
+ cloneElement,
130
+ createContext,
131
+ createElement,
132
+ createFactory,
133
+ createRef,
134
+ forwardRef,
135
+ isValidElement,
136
+ lazy,
137
+ memo,
138
+ startTransition,
139
+ useCallback,
140
+ useContext,
141
+ useDebugValue,
142
+ useDeferredValue,
143
+ useEffect,
144
+ useId,
145
+ useImperativeHandle,
146
+ useInsertionEffect,
147
+ useLayoutEffect,
148
+ useMemo,
149
+ useReducer,
150
+ useRef,
151
+ useState,
152
+ useSyncExternalStore,
153
+ useTransition,
154
+ version,
155
+ } from 'react';
156
+ `,
157
+ examples: [
158
+ {
159
+ source: 'count-down.tsx',
160
+ code: `
161
+ import React, { useEffect, useState } from '@blocklet/pages-kit/builtin/react';
162
+
163
+ export default function CountDown() {
164
+ const [count, setCount] = useState(10);
165
+ useEffect(() => {
166
+ const timer = setInterval(() => {
167
+ setCount(count - 1);
168
+ }
169
+ , 1000);
170
+ return () => clearInterval(timer);
171
+ }
172
+ , [count]);
173
+ return <div>{count}</div>;
174
+ }
175
+ `,
176
+ },
177
+ {
178
+ source: 'hello-world.tsx',
179
+ code: `
180
+ import React from '@blocklet/pages-kit/builtin/react';
181
+
182
+ export default function HelloWorld() {
183
+ return <div>Hello World</div>;
184
+ }
185
+ `,
186
+ },
187
+ ],
188
+ },
189
+ },
190
+ // '@blocklet/pages-kit/builtin/emotion/css'
191
+ {
192
+ name: '@blocklet/pages-kit/builtin/emotion/css',
193
+ description: 'A emotion/css component for pages-kit builtin package, provide css to style component',
194
+ docs: {
195
+ components: ['css'],
196
+ import: "import { css } from '@blocklet/pages-kit/builtin/emotion/css'",
197
+ export: `
198
+ export { css } from '@emotion/css';
199
+ `,
200
+ examples: [
201
+ {
202
+ source: 'css-demo.tsx',
203
+ code: `
204
+ import { css } from '@blocklet/pages-kit/builtin/emotion/css';
205
+
206
+ const style = css\`
207
+ color: hotpink;
208
+ \`;
209
+
210
+ export default function CssDemo() {
211
+ return <div className={style}>Hello World</div>;
212
+ `,
213
+ },
214
+ ],
215
+ },
216
+ },
217
+ // '@blocklet/pages-kit/builtin/mui/material'
218
+ {
219
+ name: '@blocklet/pages-kit/builtin/mui/material',
220
+ description: 'A material component for pages-kit builtin package, export a part of @mui/material',
221
+ docs: {
222
+ components: [
223
+ 'Alert',
224
+ 'AlertTitle',
225
+ 'Autocomplete',
226
+ 'Avatar',
227
+ 'Box',
228
+ 'Button',
229
+ 'ButtonGroup',
230
+ 'Card',
231
+ 'CardActionArea',
232
+ 'CardActions',
233
+ 'CardContent',
234
+ 'CardHeader',
235
+ 'CardMedia',
236
+ 'CircularProgress',
237
+ 'ClickAwayListener',
238
+ 'Collapse',
239
+ 'Container',
240
+ 'Dialog',
241
+ 'DialogActions',
242
+ 'DialogContent',
243
+ 'DialogTitle',
244
+ 'Divider',
245
+ 'Fade',
246
+ 'GlobalStyles',
247
+ 'Grid',
248
+ 'Grow',
249
+ 'LinearProgress',
250
+ 'Link',
251
+ 'List',
252
+ 'ListItem',
253
+ 'ListItemAvatar',
254
+ 'ListItemButton',
255
+ 'ListItemIcon',
256
+ 'ListItemSecondaryAction',
257
+ 'ListSubheader',
258
+ 'Menu',
259
+ 'MenuItem',
260
+ 'MenuList',
261
+ 'Paper',
262
+ 'Popper',
263
+ 'Slide',
264
+ 'Stack',
265
+ 'Switch',
266
+ 'TextField',
267
+ 'ThemeProvider',
268
+ 'Tooltip',
269
+ 'Typography',
270
+ 'Zoom',
271
+ 'alpha',
272
+ 'createTheme',
273
+ 'styled',
274
+ 'useMediaQuery',
275
+ 'useTheme',
276
+ ],
277
+ import: "import { Button } from '@blocklet/pages-kit/builtin/mui/material'",
278
+ export: `
279
+ export {
280
+ Alert,
281
+ AlertTitle,
282
+ Autocomplete,
283
+ Avatar,
284
+ Box,
285
+ Button,
286
+ ButtonGroup,
287
+ Card,
288
+ CardActionArea,
289
+ CardActions,
290
+ CardContent,
291
+ CardHeader,
292
+ CardMedia,
293
+ CircularProgress,
294
+ ClickAwayListener,
295
+ Collapse,
296
+ Container,
297
+ Dialog,
298
+ DialogActions,
299
+ DialogContent,
300
+ DialogTitle,
301
+ Divider,
302
+ Fade,
303
+ GlobalStyles,
304
+ Grid,
305
+ Grow,
306
+ LinearProgress,
307
+ Link,
308
+ List,
309
+ ListItem,
310
+ ListItemAvatar,
311
+ ListItemButton,
312
+ ListItemIcon,
313
+ ListItemSecondaryAction,
314
+ ListSubheader,
315
+ Menu,
316
+ MenuItem,
317
+ MenuList,
318
+ Paper,
319
+ Popper,
320
+ Slide,
321
+ Stack,
322
+ Switch,
323
+ TextField,
324
+ ThemeProvider,
325
+ Tooltip,
326
+ Typography,
327
+ Zoom,
328
+ alpha,
329
+ createTheme,
330
+ styled,
331
+ useMediaQuery,
332
+ useTheme,
333
+ } from '@mui/material';
334
+
335
+ `,
336
+ examples: [
337
+ {
338
+ source: 'button-demo.tsx',
339
+ code: `
340
+ import { Button } from '@blocklet/pages-kit/builtin/mui/material,';
341
+
342
+ export default function ButtonDemo() {
343
+ return <Button variant="contained">Hello World</Button>;
344
+ }
345
+ `,
346
+ },
347
+ {
348
+ source: 'alert-demo.tsx',
349
+ code: `
350
+ import { Alert } from '@blocklet/pages-kit/builtin/mui/material';
351
+
352
+ export default function AlertDemo() {
353
+ return <Alert severity="error">This is an error alert — check it out!</Alert>;
354
+ }
355
+ `,
356
+ },
357
+ ],
358
+ },
359
+ },
360
+ // '@blocklet/pages-kit/builtin/mui/lab'
361
+ {
362
+ name: '@blocklet/pages-kit/builtin/mui/lab',
363
+ description: 'A material lab component for pages-kit builtin package, export a part of @mui/lab',
364
+ docs: {
365
+ components: ['LoadingButton'],
366
+ import: "import { Button } from '@blocklet/pages-kit/builtin/mui/core'",
367
+ export: `
368
+ export { LoadingButton } from '@mui/lab';
369
+ `,
370
+ examples: [
371
+ {
372
+ source: 'loading-button-demo.tsx',
373
+ code: `
374
+ import { LoadingButton } from '@blocklet/pages-kit/builtin/mui/lab';
375
+
376
+ export default function LoadingButtonDemo() {
377
+ return <LoadingButton loading variant="contained">Hello World</LoadingButton>;
378
+ }
379
+ `,
380
+ },
381
+ ],
382
+ },
383
+ },
384
+ // '@blocklet/pages-kit/builtin/react-hook-form'
385
+ {
386
+ name: '@blocklet/pages-kit/builtin/react-hook-form',
387
+ description: 'A react-hook-form component for pages-kit builtin package, use react-hook-form to manage form state',
388
+ docs: {
389
+ components: ['useForm', 'useFieldArray', 'useWatch', 'Controller', 'useFormContext'],
390
+ import: "import * as reactHookForm from '@blocklet/pages-kit/builtin/react-hook-form'",
391
+ export: "export * from 'react-hook-form';",
392
+ examples: [
393
+ {
394
+ source: 'form-demo.tsx',
395
+ code: `
396
+ import { useForm } from '@blocklet/pages-kit/builtin/react-hook-form';
397
+
398
+ export default function FormDemo() {
399
+ const { register, handleSubmit } = useForm();
400
+ const onSubmit = (data) => {
401
+ console.log(data);
402
+ };
403
+ return (
404
+ <form onSubmit={handleSubmit(onSubmit)}>
405
+ <input {...register('name')} />
406
+ <button type="submit">Submit</button>
407
+ </form>
408
+ );
409
+ }`,
410
+ },
411
+ ],
412
+ },
413
+ },
414
+ // '@blocklet/pages-kit/builtin/iconify/react'
415
+ {
416
+ name: '@blocklet/pages-kit/builtin/iconify/react',
417
+ description: 'A iconify/react component for pages-kit builtin package, all icons use this component',
418
+ docs: {
419
+ components: ['Icon'],
420
+ import: 'import { Icon } from "@blocklet/pages-kit/builtin/iconify/react"',
421
+ export: "export { Icon } from '@iconify/react';",
422
+ examples: [
423
+ {
424
+ source: 'tabler-success-icon.tsx',
425
+ code: `
426
+ import { Icon } from '@blocklet/pages-kit/builtin/iconify/react';
427
+
428
+ export default function TablerSuccessIcon() {
429
+ return <Icon icon="tabler:check" />;
430
+ }
431
+ `,
432
+ },
433
+ ],
434
+ },
435
+ },
436
+ // '@blocklet/pages-kit/builtin/zustand'
437
+ {
438
+ name: '@blocklet/pages-kit/builtin/zustand',
439
+ description: 'A zustand component for pages-kit builtin package, use zustand to manage global state',
440
+ docs: {
441
+ components: [
442
+ // include all zustand hooks
443
+ 'create',
444
+ 'useStore',
445
+ 'createStore',
446
+ ],
447
+ import: "import * as zustand from '@blocklet/pages-kit/builtin/zustand'",
448
+ export: "export * from 'zustand';",
449
+ examples: [
450
+ {
451
+ source: 'counter.tsx',
452
+ code: `
453
+ import { create } from '@blocklet/pages-kit/builtin/zustand';
454
+
455
+ export const useStore = create((set) => ({
456
+ count: 0,
457
+ inc: () => set((state) => ({ count: state.count + 1 })),
458
+ dec: () => set((state) => ({ count: state.count - 1 })),
459
+ }));
460
+
461
+ export default function Counter() {
462
+ const { count, inc, dec } = useStore();
463
+ return (
464
+ <div>
465
+ {count}
466
+ <button onClick={inc}>+</button>
467
+ <button onClick={dec}>-</button>
468
+ </div>
469
+ );
470
+ }
471
+ `,
472
+ },
473
+ ],
474
+ },
475
+ },
476
+ // '@blocklet/pages-kit/builtin/zustand/middleware/immer'
477
+ {
478
+ name: '@blocklet/pages-kit/builtin/zustand/middleware/immer',
479
+ description: 'A immer middleware for zustand component in pages-kit builtin package, use immer to manage global state',
480
+ docs: {
481
+ components: ['immer'],
482
+ import: "import * as zustandImmer from '@blocklet/pages-kit/builtin/zustand/middleware/immer'",
483
+ export: "export * from 'zustand/middleware/immer';",
484
+ examples: [
485
+ {
486
+ source: 'immer-global-loading-state.tsx',
487
+ code: `
488
+ import { create } from '@blocklet/pages-kit/builtin/zustand';
489
+ import { immer } from '@blocklet/pages-kit/builtin/zustand/middleware/immer';
490
+
491
+ export interface GlobalLoadingState {
492
+ loading: boolean;
493
+ count: number;
494
+ run: <T>(fn: Promise<T> | (() => Promise<T>)) => Promise<T>;
495
+ start: () => void;
496
+ end: () => void;
497
+ }
498
+
499
+ export const globalLoadingState = create<GlobalLoadingState>()(
500
+ immer((set, get) => ({
501
+ loading: false,
502
+ count: 0,
503
+ run: async (fn: Promise<any> | (() => any)) => {
504
+ try {
505
+ get().start();
506
+ return (await (typeof fn === 'function' ? fn() : fn)) as any;
507
+ } finally {
508
+ get().end();
509
+ }
510
+ },
511
+ start: () => {
512
+ set((state) => {
513
+ state.count += 1;
514
+ state.loading = true;
515
+ });
516
+ },
517
+ end: () => {
518
+ set((state) => {
519
+ state.count = Math.max(0, state.count - 1);
520
+ state.loading = state.count > 0;
521
+ });
522
+ },
523
+ }))
524
+ );
525
+
526
+ `,
527
+ },
528
+ ],
529
+ },
530
+ },
531
+ // '@blocklet/pages-kit/builtin/immer'
532
+ {
533
+ name: '@blocklet/pages-kit/builtin/immer',
534
+ description: 'A immer component for pages-kit builtin package',
535
+ docs: {
536
+ components: ['original', 'produce'],
537
+ import: "import * as immer from '@blocklet/pages-kit/builtin/immer'",
538
+ export: "export * from 'immer';",
539
+ examples: [
540
+ {
541
+ source: 'immer-demo.tsx',
542
+ code: `
543
+ import { original, produce } from '@blocklet/pages-kit/builtin/immer';
544
+
545
+ export default function ImmerDemo() {
546
+ const [state, setState] = useState({ count: 0 });
547
+
548
+ const increment = () => {
549
+ setState(
550
+ produce((draft) => {
551
+ draft.count += 1;
552
+ })
553
+ );
554
+ }
555
+
556
+ const reset = () => {
557
+ setState(
558
+ produce((draft) => {
559
+ draft.count = 0;
560
+ })
561
+ );
562
+ }
563
+
564
+ return (
565
+ <div>
566
+ <div>{state.count}</div>
567
+ <button onClick={increment}>Increment</button>
568
+ <button onClick={reset}>Reset</button>
569
+ </div>
570
+ );
571
+ }
572
+ `,
573
+ },
574
+ ],
575
+ },
576
+ },
577
+ // '@blocklet/pages-kit/builtin/react-wrap-balancer'
578
+ {
579
+ name: '@blocklet/pages-kit/builtin/react-wrap-balancer',
580
+ description: 'A react-wrap-balancer component for pages-kit builtin package, use to manage text wrap balance',
581
+ docs: {
582
+ components: ['Balancer'],
583
+ import: "import * as ReactWrapperBlancer from '@blocklet/pages-kit/builtin/react-wrap-balancer'",
584
+ export: `
585
+ import Balancer from 'react-wrap-balancer';
586
+
587
+ export default Balancer;
588
+
589
+ export * from 'react-wrap-balancer';
590
+
591
+ `,
592
+ examples: [
593
+ {
594
+ source: 'balancer-text-demo.tsx',
595
+ code: `
596
+ import Balancer from '@blocklet/pages-kit/builtin/react-wrap-balancer';
597
+
598
+ export default function BalancerTextDemo() {
599
+ return <Balancer>
600
+ <div>
601
+ <p>hello world</p>
602
+ <p>I am soooooooooooooo long text to wait balance</p>
603
+ </div>
604
+ </Balancer>;
605
+ }
606
+ `,
607
+ },
608
+ ],
609
+ },
610
+ },
611
+ // '@blocklet/pages-kit/builtin/call'
612
+ {
613
+ name: '@blocklet/pages-kit/builtin/call',
614
+ description: "A call component for pages-kit builtin package, use to call other blocklet's api",
615
+ docs: {
616
+ components: ['call'],
617
+ import: "import * as call from '@blocklet/pages-kit/builtin/call'",
618
+ export: `
619
+ import { getComponentMountPoint, joinURL, withQuery } from './utils';
620
+
621
+ export interface CallInput {
622
+ name: string;
623
+ path: string;
624
+ method: string;
625
+ headers?: { [key: string]: any };
626
+ query?: { [key: string]: any };
627
+ body?: any;
628
+ }
629
+
630
+ export async function call(input: CallInput) {
631
+ // call component directly at server side
632
+ if (typeof window === 'undefined') {
633
+ const { getComponentWebEndpoint }: typeof import('@blocklet/sdk/lib/component') =
634
+ // eslint-disable-next-line global-require
635
+ require('@blocklet/sdk/lib/component');
636
+ const { sign }: typeof import('@blocklet/sdk/lib/util/verify-sign') =
637
+ // eslint-disable-next-line global-require
638
+ require('@blocklet/sdk/lib/util/verify-sign');
639
+
640
+ const fetch: typeof import('node-fetch') =
641
+ // eslint-disable-next-line global-require
642
+ require('node-fetch');
643
+
644
+ return fetch(withQuery(joinURL(getComponentWebEndpoint(input.name), input.path), input.query ?? {}), {
645
+ method: input.method,
646
+ headers: {
647
+ ...input.headers,
648
+ 'x-component-sig': sign(input.body ?? {}),
649
+ 'x-component-did': process.env.BLOCKLET_COMPONENT_DID!,
650
+ 'Content-Type': 'application/json',
651
+ },
652
+ body:
653
+ typeof input.body !== 'undefined' && input.method.toLowerCase() !== 'get'
654
+ ? JSON.stringify(input.body)
655
+ : undefined,
656
+ });
657
+ }
658
+
659
+ const prefix = getComponentMountPoint('pages-kit');
660
+ return fetch(joinURL(prefix!, '/api/call'), {
661
+ method: 'POST',
662
+ headers: {
663
+ ...input.headers,
664
+ 'Content-Type': 'application/json',
665
+ },
666
+ body: JSON.stringify(input),
667
+ });
668
+ }
669
+ `,
670
+ examples: [
671
+ {
672
+ source: 'ai-call-demo.tsx',
673
+ code: `
674
+ import { call } from '@blocklet/pages-kit/builtin/call';
675
+ import { useState } from '@blocklet/pages-kit/builtin/react';
676
+
677
+ export default AICallInput(){
678
+ const [result, setResult] = useState();
679
+ const [loading, setLoading] = useState(false);
680
+
681
+ const handleCall = async () => {
682
+ setLoading(true);
683
+ const res = await call({
684
+ name: 'ai-kit',
685
+ path: '/api/v1/sdk/completions',
686
+ method: 'POST',
687
+ body: {
688
+ text: 'hello world',
689
+ },
690
+ });
691
+ const data = await res.json();
692
+ setResult(data);
693
+ setLoading(false);
694
+ };
695
+
696
+ return (
697
+ <div>
698
+ <button onClick={handleCall}>Call AI</button>
699
+ {loading && <div>Loading...</div>}
700
+ {result && <div>{result}</div>}
701
+ </div>
702
+ );
703
+ }
704
+ `,
705
+ },
706
+ ],
707
+ },
708
+ },
709
+ // '@blocklet/pages-kit/builtin/stream'
710
+ {
711
+ name: '@blocklet/pages-kit/builtin/stream',
712
+ description: 'A stream component for pages-kit builtin package',
713
+ docs: {
714
+ components: ['EventSourceParserStream'],
715
+ import: "import * as stream from '@blocklet/pages-kit/builtin/stream'",
716
+ export: `
717
+ import { createParser } from 'eventsource-parser';
718
+
719
+ const requireNodeJs = typeof require !== 'undefined' ? require : undefined;
720
+
721
+ const TransformStream: typeof globalThis.TransformStream =
722
+ typeof window !== 'undefined' || !requireNodeJs
723
+ ? globalThis.TransformStream
724
+ : requireNodeJs('stream/web').TransformStream;
725
+
726
+ export class EventSourceParserStream<T> extends TransformStream<any, T> {
727
+ constructor() {
728
+ let parser: ReturnType<typeof createParser> | undefined;
729
+
730
+ super({
731
+ start(controller) {
732
+ parser = createParser((event) => {
733
+ if (event.type === 'event') {
734
+ try {
735
+ const json = JSON.parse(event.data) as T;
736
+ controller.enqueue(json);
737
+ } catch (error) {
738
+ console.error('parse chunk error', { error, data: event.data });
739
+ }
740
+ }
741
+ });
742
+ },
743
+ transform(chunk) {
744
+ parser?.feed(chunk);
745
+ },
746
+ });
747
+ }
748
+ }
749
+ `,
750
+ examples: [],
751
+ },
752
+ },
753
+ // '@blocklet/pages-kit/builtin/session'
754
+ {
755
+ name: '@blocklet/pages-kit/builtin/session',
756
+ description: 'A session component for pages-kit builtin package, use to manage user session, export from @arcblock/did-connect/lib/Session',
757
+ docs: {
758
+ components: ['useSessionContext'],
759
+ import: "import * as authSession from '@blocklet/pages-kit/builtin/session'",
760
+ export: `
761
+ import { SessionContext } from '@arcblock/did-connect/lib/Session';
762
+ import { useContext } from 'react';
763
+
764
+ export function useSessionContext(): {
765
+ session: {
766
+ user?: { did: string; fullName: string; avatar: string };
767
+ loading?: boolean;
768
+ login: (cb?: () => void) => any;
769
+ };
770
+ } {
771
+ return useContext(SessionContext);
772
+ }
773
+ `,
774
+ examples: [
775
+ {
776
+ source: 'current-user-did.tsx',
777
+ code: `
778
+ import { useSessionContext } from '@blocklet/pages-kit/builtin/session';
779
+
780
+ export default function CurrentUserDid() {
781
+ const { session } = useSessionContext();
782
+ return <div>{session.user?.did}</div>;
783
+ }
784
+ `,
785
+ },
786
+ ],
787
+ },
788
+ },
789
+ // '@blocklet/pages-kit/builtin/locale'
790
+ {
791
+ name: '@blocklet/pages-kit/builtin/locale',
792
+ description: 'A locale component for pages-kit builtin package, use to manage i18n locale',
793
+ docs: {
794
+ components: ['LocaleProvider', 'useLocaleContext'],
795
+ import: "import * as locale from '@blocklet/pages-kit/builtin/locale'",
796
+ export: "export { LocaleProvider, useLocaleContext } from '@arcblock/ux/lib/Locale/context';",
797
+ examples: [
798
+ {
799
+ source: 'locale-demo.tsx',
800
+ code: `
801
+ import { LocaleProvider, useLocaleContext } from '@blocklet/pages-kit/builtin/locale';
802
+
803
+ const translations = {
804
+ en: {
805
+ hello: 'Hello',
806
+ },
807
+ zh: {
808
+ hello: '你好',
809
+ },
810
+ };
811
+
812
+ const LocaleHello = () => {
813
+ const { t } = useLocaleContext();
814
+ return <div>{t('hello')}</div>;
815
+ }
816
+
817
+ export default LocalDemo(){
818
+ const { locale } = useLocaleContext();
819
+
820
+ return (
821
+ <LocaleProvider translations={translations} locale={locale} fallbackLocale="en">
822
+ <LocaleHello />
823
+ </LocaleProvider>
824
+ );
825
+ };
826
+ `,
827
+ },
828
+ ],
829
+ },
830
+ },
831
+ // '@blocklet/pages-kit/builtin/react-router-dom'
832
+ {
833
+ name: '@blocklet/pages-kit/builtin/react-router-dom',
834
+ description: 'A react-router-dom component for pages-kit builtin package, export from react-router-dom',
835
+ docs: {
836
+ components: [
837
+ 'BrowserRouter',
838
+ 'HashRouter',
839
+ 'Link',
840
+ 'NavLink',
841
+ 'Route',
842
+ 'Router',
843
+ 'Switch',
844
+ 'useHistory',
845
+ 'useLocation',
846
+ 'useParams',
847
+ 'useRouteMatch',
848
+ ],
849
+ import: "import * as reactRouterDom from '@blocklet/pages-kit/builtin/react-router-dom'",
850
+ export: "export * from 'react-router-dom';",
851
+ examples: [
852
+ {
853
+ source: 'navigator-to-other-page.tsx',
854
+ code: `
855
+ import { Link } from '@blocklet/pages-kit/builtin/react-router-dom';
856
+
857
+ export default function NavigatorToOtherPage() {
858
+ return <Link to="/other-page">Go to other page</Link>;
859
+ }
860
+ `,
861
+ },
862
+ {
863
+ source: 'use-location.tsx',
864
+ code: `
865
+ import { useLocation } from '@blocklet/pages-kit/builtin/react-router-dom';
866
+
867
+ export default function UseLocation() {
868
+ const location = useLocation();
869
+ return <div>{location.pathname} {location.search}</div>;
870
+ }
871
+ `,
872
+ },
873
+ ],
874
+ },
875
+ },
876
+ // '@blocklet/pages-kit/builtin/arcblock/ux'
877
+ {
878
+ name: '@blocklet/pages-kit/builtin/arcblock/ux',
879
+ description: 'A arcblock/ux component for pages-kit builtin package, export a part of @arcblock/ux',
880
+ docs: {
881
+ components: ['RelativeTime', 'DID', 'Avatar', 'Address', 'Result', 'Toast'],
882
+ import: "import * as arcblockUx from '@blocklet/pages-kit/builtin/arcblock/ux'",
883
+ export: `
884
+ export { default as RelativeTime } from '@arcblock/ux/lib/RelativeTime';
885
+ export { default as DID } from '@arcblock/ux/lib/DID';
886
+ export { default as Avatar } from '@arcblock/ux/lib/Avatar';
887
+ export { default as Address } from '@arcblock/ux/lib/Address';
888
+ export { default as Result } from '@arcblock/ux/lib/Result';
889
+ export { default as Toast } from '@arcblock/ux/lib/Toast';
890
+ `,
891
+ examples: [
892
+ {
893
+ source: 'relative-time-demo.tsx',
894
+ code: `
895
+ import { RelativeTime } from '@blocklet/pages-kit/builtin/arcblock/ux';
896
+
897
+ export default ShowRelativeTime() {
898
+ return <div>
899
+ Relative Time:
900
+ <RelativeTime value={new Date()} />
901
+ </div>
902
+ }
903
+ `,
904
+ },
905
+ {
906
+ source: 'show-did-demo.tsx',
907
+ code: `
908
+ import { DID } from '@blocklet/pages-kit/builtin/arcblock/ux';
909
+
910
+ export default ShowDIDDemo() {
911
+ return <div>
912
+ DID:
913
+ <DID did="z1dnPVvKHWNuSBdk1FC1gNC1oYKi73CqADX" copyable={false} />
914
+ </div>
915
+ }
916
+ `,
917
+ },
918
+ ],
919
+ },
920
+ },
921
+ // '@blocklet/pages-kit/builtin/page/header'
922
+ {
923
+ name: '@blocklet/pages-kit/builtin/page/header',
924
+ description: 'A header component for pages-kit builtin package, use to manage header state',
925
+ docs: {
926
+ components: ['useHeaderState'],
927
+ import: "import * as headerState from '@blocklet/pages-kit/builtin/page/header'",
928
+ export: `
929
+ import { create } from 'zustand';
930
+ import { immer } from 'zustand/middleware/immer';
931
+
932
+ export interface HeaderState {
933
+ logo?: any;
934
+ brand?: any;
935
+ description?: any;
936
+ addons?: (...exists: any[]) => any[];
937
+ }
938
+
939
+ export const useHeaderState = create<HeaderState>()(immer(() => ({})));
940
+ `,
941
+ examples: [
942
+ {
943
+ source: 'header-state-demo.tsx',
944
+ code: `
945
+ import { useHeaderState } from '@blocklet/pages-kit/builtin/page/header';
946
+
947
+ export default function HeaderStateDemo() {
948
+ const { logo, brand, description, setState } = useHeaderState();
949
+
950
+ const setHeader = () => {
951
+ setState((state) => {
952
+ state.logo = 'https://arcblock.io/logo.png';
953
+ state.brand = 'ArcBlock';
954
+ state.description = 'ArcBlock is a blockchain platform for building decentralized applications';
955
+ });
956
+ }
957
+ return <div>
958
+ {logo} {brand} {description}
959
+ <button onClick={setHeader} >Set Header</button>
960
+ </div>
961
+ }
962
+ `,
963
+ },
964
+ ],
965
+ },
966
+ },
967
+ // // The following packages are lazy loading
968
+ // '@blocklet/pages-kit/builtin/async/react-scroll-to-bottom'
969
+ {
970
+ name: '@blocklet/pages-kit/builtin/async/react-scroll-to-bottom',
971
+ description: 'A react-scroll-to-bottom component for pages-kit builtin package',
972
+ docs: {
973
+ components: ['ScrollToBottom'],
974
+ import: "import * as ScrollToBottom from '@blocklet/pages-kit/builtin/async/react-scroll-to-bottom'",
975
+ export: `
976
+ export default () =>
977
+ Promise.all([
978
+ import('react-scroll-to-bottom'),
979
+ typeof window !== 'undefined'
980
+ ? // @ts-ignore
981
+ import('react-scroll-to-bottom/lib/esm/hooks/internal/useInternalContext')
982
+ : // @ts-ignore
983
+ import('react-scroll-to-bottom/lib/hooks/internal/useInternalContext'),
984
+ ]).then(([mod, { default: useInternalContext }]) => ({
985
+ ...mod,
986
+ Composer: (mod as any).Composer as typeof mod.default,
987
+ useInternalContext,
988
+ }));
989
+ `,
990
+ examples: [],
991
+ },
992
+ },
993
+ // '@blocklet/pages-kit/builtin/async/react-markdown'
994
+ {
995
+ name: '@blocklet/pages-kit/builtin/async/react-markdown',
996
+ description: 'A react-markdown component for pages-kit builtin package',
997
+ docs: {
998
+ components: ['ReactMarkdown'],
999
+ import: "import * as ReactMarkdown from '@blocklet/pages-kit/builtin/async/react-markdown'",
1000
+ export: "export default () => import('react-markdown');",
1001
+ examples: [],
1002
+ },
1003
+ },
1004
+ // '@blocklet/pages-kit/builtin/async/react-syntax-highlighter'
1005
+ {
1006
+ name: '@blocklet/pages-kit/builtin/async/react-syntax-highlighter',
1007
+ description: 'A react-syntax-highlighter component for pages-kit builtin package',
1008
+ docs: {
1009
+ components: ['ReactSyntaxHighlighter'],
1010
+ import: "import * as ReactSyntaxHighlighter from '@blocklet/pages-kit/builtin/async/react-syntax-highlighter'",
1011
+ export: "export default () => import('react-syntax-highlighter');",
1012
+ examples: [],
1013
+ },
1014
+ },
1015
+ // '@blocklet/pages-kit/builtin/async/image-preview'
1016
+ {
1017
+ name: '@blocklet/pages-kit/builtin/async/image-preview',
1018
+ description: 'A image-preview component for pages-kit builtin package',
1019
+ docs: {
1020
+ components: ['ImagePreview'],
1021
+ import: "import * as ImagePreview from '@blocklet/pages-kit/builtin/async/image-preview'",
1022
+ export: "export default () => import('@blocklet/ai-kit/components/image-preview');",
1023
+ examples: [],
1024
+ },
1025
+ },
1026
+ // '@blocklet/pages-kit/builtin/async/ai-runtime'
1027
+ {
1028
+ name: '@blocklet/pages-kit/builtin/async/ai-runtime',
1029
+ description: 'A ai-runtime component for pages-kit builtin package',
1030
+ docs: {
1031
+ components: [
1032
+ 'CurrentAgent',
1033
+ 'CurrentAgentProvider',
1034
+ 'CurrentMessage',
1035
+ 'CurrentMessageProvider',
1036
+ 'Runtime',
1037
+ 'ChatBotButton',
1038
+ 'SimplePage',
1039
+ 'SimpleChat',
1040
+ 'PhotoGallery',
1041
+ 'AutoForm',
1042
+ 'SimpleOutput',
1043
+ 'ChatOutput',
1044
+ 'PhotoGalleryItem',
1045
+ ],
1046
+ import: "import * as AiRuntime from '@blocklet/pages-kit/builtin/async/ai-runtime'",
1047
+ export: `
1048
+ export * from './contexts/CurrentAgent';
1049
+ export { default as CurrentAgentProvider } from './contexts/CurrentAgent';
1050
+
1051
+ export * from './contexts/CurrentMessage';
1052
+ export { default as CurrentMessageProvider } from './contexts/CurrentMessage';
1053
+
1054
+ export * from './state/runtime';
1055
+ export * from './state/session';
1056
+
1057
+ export { default as Runtime } from './runtime/Runtime';
1058
+ export { default as ChatBotButton } from './runtime/ChatBotButton';
1059
+
1060
+ export { default as SimplePage } from './runtime-components/SimplePage';
1061
+ export { default as SimpleChat } from './runtime-components/SimpleChat';
1062
+ export { default as PhotoGallery } from './runtime-components/PhotoGallery';
1063
+ export { default as AutoForm } from './runtime-components/AutoForm';
1064
+ export { default as SimpleOutput } from './runtime-components/SimpleOutput';
1065
+ export { default as ChatOutput } from './runtime-components/ChatOutput';
1066
+ export { default as PhotoGalleryItem } from './runtime-components/PhotoGalleryItem';
1067
+ `,
1068
+ examples: [],
1069
+ },
1070
+ },
1071
+ // '@blocklet/pages-kit/builtin/pages-kit'
1072
+ {
1073
+ name: '@blocklet/pages-kit/builtin/pages-kit',
1074
+ description: 'A pages-kit component for pages-kit builtin package',
1075
+ docs: {
1076
+ components: ['CustomComponentRenderer'],
1077
+ import: "import * as pagesKitBuiltin from '@blocklet/pages-kit/builtin/pages-kit'",
1078
+ export: `export {
1079
+ CustomComponentRenderer
1080
+ }`,
1081
+ examples: [
1082
+ {
1083
+ source: 'local-custom-component-renderer.tsx',
1084
+ code: `
1085
+ import { CustomComponentRenderer } from '@blocklet/pages-kit/builtin/pages-kit';
1086
+
1087
+ export default function LocalCustomComponentRendererDemo({ code }) {
1088
+ return (
1089
+ <CustomComponentRenderer
1090
+ componentId="mock-dev-component"
1091
+ dev={{
1092
+ components: {
1093
+ 'mock-dev-component': {
1094
+ data: {
1095
+ id: 'mock-dev-component',
1096
+ createdAt: '',
1097
+ updatedAt: '',
1098
+ renderer: {
1099
+ type: 'react-component',
1100
+ script: code,
1101
+ },
1102
+ },
1103
+ },
1104
+ },
1105
+ }}
1106
+ />);
1107
+ }`,
1108
+ },
1109
+ ],
1110
+ },
1111
+ },
1112
+ ];
1113
+ // set dumpJSON to AI Studio knowledge
1114
+ const shouldUpdateKnowledge = true;
1115
+ const cookie = 'CookieConsent=true; _ga=GA1.2.1343579140.1705048750; _ga_B1V5Y6VTCW=GS1.2.1705048750.1.1.1705049433.0.0.0; __stripe_mid=b799e3a9-894f-4069-aa7b-731906316d4b34cd93; nf_lang=zh; login_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0eXBlIjoidXNlciIsImRpZCI6InoxVENDb21nQ0pOSGJIV2V0VFdHZGhQQjZOWVoyUmVEakx1Iiwicm9sZSI6Im93bmVyIiwicHJvdmlkZXIiOiJ3YWxsZXQiLCJ3YWxsZXRPUyI6IndlYiIsInBhc3Nwb3J0Ijp7ImlkIjoiejJpVHkyWkRUdENIamJLNEh6ZXQ5U25aR2pjRnRYODFHTjk4ViJ9LCJmdWxsTmFtZSI6Illvbmd6aHVvIExpYW5nIiwiaWF0IjoxNzE1OTEwMTM1LCJleHAiOjE3MTU5MTM3MzV9.jjkmYahNt9ZDSRtwdPek2Mf-lCzmU9CORPL40fwAN0A';
1116
+ const aiStudioUrl = 'https://bbqa2t5pfyfroyobmzknmktshckzto4btkfagxyjqwy.did.abtnet.io/ai-studio';
1117
+ const datasetId = '443696818363039744';
1118
+ if (cookie && shouldUpdateKnowledge && aiStudioUrl && datasetId) {
1119
+ const baseUrl = (0, ufo_1.joinURL)(aiStudioUrl, '/api/datasets', datasetId, 'documents');
1120
+ fetch(`${baseUrl}?page=1&size=100`, {
1121
+ headers: {
1122
+ cookie,
1123
+ 'Content-Type': 'application/json',
1124
+ },
1125
+ })
1126
+ .then((res) => res.json())
1127
+ .then(({ items }) => {
1128
+ console.info('items count: ', items === null || items === void 0 ? void 0 : items.length);
1129
+ const successText = (data) => {
1130
+ console.info(`${data.name} success`);
1131
+ };
1132
+ dumpJSON.forEach((item) => {
1133
+ // if items exist, update it
1134
+ const itemInKnowledge = items.find((i) => i.name === item.name);
1135
+ if (itemInKnowledge) {
1136
+ fetch((0, ufo_1.joinURL)(baseUrl, itemInKnowledge.id, 'text'), {
1137
+ method: 'PUT',
1138
+ headers: {
1139
+ cookie,
1140
+ 'Content-Type': 'application/json',
1141
+ },
1142
+ body: JSON.stringify({
1143
+ content: JSON.stringify(item, null, 2),
1144
+ name: item.name,
1145
+ }),
1146
+ })
1147
+ .then((res) => res.json())
1148
+ .then(successText);
1149
+ }
1150
+ else {
1151
+ fetch((0, ufo_1.joinURL)(baseUrl, 'text'), {
1152
+ method: 'POST',
1153
+ headers: {
1154
+ cookie,
1155
+ 'Content-Type': 'application/json',
1156
+ },
1157
+ body: JSON.stringify({
1158
+ content: JSON.stringify(item, null, 2),
1159
+ name: item.name,
1160
+ }),
1161
+ })
1162
+ .then((res) => res.json())
1163
+ .then(successText);
1164
+ }
1165
+ });
1166
+ });
1167
+ }