@blocklet/pages-kit 0.2.228 → 0.2.230

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.
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.call = void 0;
13
+ const utils_1 = require("./utils");
14
+ function call(input) {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ const prefix = (0, utils_1.getComponentMountPoint)('pages-kit');
17
+ return fetch((0, utils_1.joinURL)(prefix, '/api/call'), {
18
+ method: 'POST',
19
+ headers: Object.assign(Object.assign({}, input.headers), { 'Content-Type': 'application/json' }),
20
+ body: JSON.stringify(input),
21
+ });
22
+ });
23
+ }
24
+ exports.call = call;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useSessionContext = exports.SessionContext = void 0;
4
+ const Session_1 = require("@arcblock/did-connect/lib/Session");
5
+ const react_1 = require("react");
6
+ var Session_2 = require("@arcblock/did-connect/lib/Session");
7
+ Object.defineProperty(exports, "SessionContext", { enumerable: true, get: function () { return Session_2.SessionContext; } });
8
+ function useSessionContext() {
9
+ return (0, react_1.useContext)(Session_1.SessionContext);
10
+ }
11
+ exports.useSessionContext = useSessionContext;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EventSourceParserStream = void 0;
4
+ const eventsource_parser_1 = require("eventsource-parser");
5
+ class EventSourceParserStream extends TransformStream {
6
+ constructor() {
7
+ let parser;
8
+ super({
9
+ start(controller) {
10
+ parser = (0, eventsource_parser_1.createParser)((event) => {
11
+ if (event.type === 'event') {
12
+ try {
13
+ const json = JSON.parse(event.data);
14
+ controller.enqueue(json);
15
+ }
16
+ catch (error) {
17
+ console.error('parse chunk error', { error, data: event.data });
18
+ }
19
+ }
20
+ });
21
+ },
22
+ transform(chunk) {
23
+ parser === null || parser === void 0 ? void 0 : parser.feed(chunk);
24
+ },
25
+ });
26
+ }
27
+ }
28
+ exports.EventSourceParserStream = EventSourceParserStream;
@@ -23,12 +23,15 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
+ const call = __importStar(require("../builtin/call"));
26
27
  const builtinIconifyReact = __importStar(require("../builtin/iconify/react"));
27
28
  const builtinMuiLab = __importStar(require("../builtin/mui/lab"));
28
29
  const builtinMuiMaterial = __importStar(require("../builtin/mui/material"));
29
30
  const builtinReact = __importStar(require("../builtin/react"));
30
31
  const builtinReactHookForm = __importStar(require("../builtin/react-hook-form"));
31
32
  const reactWrapBalancer = __importStar(require("../builtin/react-wrap-balancer"));
33
+ const session = __importStar(require("../builtin/session"));
34
+ const stream = __importStar(require("../builtin/stream"));
32
35
  const builtinUtils = __importStar(require("../builtin/utils"));
33
36
  const builtinZustand = __importStar(require("../builtin/zustand"));
34
37
  const builtinZustandMiddlewareImmer = __importStar(require("../builtin/zustand/middleware/immer"));
@@ -46,6 +49,9 @@ function injectGlobalComponents() {
46
49
  '@blocklet/pages-kit/builtin/zustand': builtinZustand,
47
50
  '@blocklet/pages-kit/builtin/zustand/middleware/immer': builtinZustandMiddlewareImmer,
48
51
  '@blocklet/pages-kit/builtin/react-wrap-balancer': reactWrapBalancer,
52
+ '@blocklet/pages-kit/builtin/call': call,
53
+ '@blocklet/pages-kit/builtin/stream': stream,
54
+ '@blocklet/pages-kit/builtin/session': session,
49
55
  },
50
56
  require(module) {
51
57
  return win[builtin_1.BuiltinModulesGlobalVariableName].modules[module];
@@ -0,0 +1,20 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { getComponentMountPoint, joinURL } from './utils';
11
+ export function call(input) {
12
+ return __awaiter(this, void 0, void 0, function* () {
13
+ const prefix = getComponentMountPoint('pages-kit');
14
+ return fetch(joinURL(prefix, '/api/call'), {
15
+ method: 'POST',
16
+ headers: Object.assign(Object.assign({}, input.headers), { 'Content-Type': 'application/json' }),
17
+ body: JSON.stringify(input),
18
+ });
19
+ });
20
+ }
@@ -0,0 +1,6 @@
1
+ import { SessionContext } from '@arcblock/did-connect/lib/Session';
2
+ import { useContext } from 'react';
3
+ export { SessionContext } from '@arcblock/did-connect/lib/Session';
4
+ export function useSessionContext() {
5
+ return useContext(SessionContext);
6
+ }
@@ -0,0 +1,24 @@
1
+ import { createParser } from 'eventsource-parser';
2
+ export class EventSourceParserStream extends TransformStream {
3
+ constructor() {
4
+ let parser;
5
+ super({
6
+ start(controller) {
7
+ parser = createParser((event) => {
8
+ if (event.type === 'event') {
9
+ try {
10
+ const json = JSON.parse(event.data);
11
+ controller.enqueue(json);
12
+ }
13
+ catch (error) {
14
+ console.error('parse chunk error', { error, data: event.data });
15
+ }
16
+ }
17
+ });
18
+ },
19
+ transform(chunk) {
20
+ parser === null || parser === void 0 ? void 0 : parser.feed(chunk);
21
+ },
22
+ });
23
+ }
24
+ }
@@ -1,9 +1,12 @@
1
+ import * as call from '../builtin/call';
1
2
  import * as builtinIconifyReact from '../builtin/iconify/react';
2
3
  import * as builtinMuiLab from '../builtin/mui/lab';
3
4
  import * as builtinMuiMaterial from '../builtin/mui/material';
4
5
  import * as builtinReact from '../builtin/react';
5
6
  import * as builtinReactHookForm from '../builtin/react-hook-form';
6
7
  import * as reactWrapBalancer from '../builtin/react-wrap-balancer';
8
+ import * as session from '../builtin/session';
9
+ import * as stream from '../builtin/stream';
7
10
  import * as builtinUtils from '../builtin/utils';
8
11
  import * as builtinZustand from '../builtin/zustand';
9
12
  import * as builtinZustandMiddlewareImmer from '../builtin/zustand/middleware/immer';
@@ -21,6 +24,9 @@ function injectGlobalComponents() {
21
24
  '@blocklet/pages-kit/builtin/zustand': builtinZustand,
22
25
  '@blocklet/pages-kit/builtin/zustand/middleware/immer': builtinZustandMiddlewareImmer,
23
26
  '@blocklet/pages-kit/builtin/react-wrap-balancer': reactWrapBalancer,
27
+ '@blocklet/pages-kit/builtin/call': call,
28
+ '@blocklet/pages-kit/builtin/stream': stream,
29
+ '@blocklet/pages-kit/builtin/session': session,
24
30
  },
25
31
  require(module) {
26
32
  return win[BuiltinModulesGlobalVariableName].modules[module];
@@ -0,0 +1,13 @@
1
+ export interface CallInput {
2
+ name: string;
3
+ path: string;
4
+ method: string;
5
+ headers?: {
6
+ [key: string]: any;
7
+ };
8
+ query?: {
9
+ [key: string]: any;
10
+ };
11
+ body?: any;
12
+ }
13
+ export declare function call(input: CallInput): Promise<Response>;
@@ -0,0 +1,2 @@
1
+ export { SessionContext } from '@arcblock/did-connect/lib/Session';
2
+ export declare function useSessionContext(): unknown;
@@ -0,0 +1,3 @@
1
+ export declare class EventSourceParserStream<T> extends TransformStream<any, T> {
2
+ constructor();
3
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/pages-kit",
3
- "version": "0.2.228",
3
+ "version": "0.2.230",
4
4
  "description": "Pages Kit components and utils",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -93,9 +93,11 @@
93
93
  "prepare": "npm run build"
94
94
  },
95
95
  "dependencies": {
96
+ "@arcblock/did-connect": "^2.9.26",
96
97
  "@blocklet/sdk": "^1.16.22",
97
98
  "@iconify/react": "^4.1.1",
98
99
  "axios": "^1.6.7",
100
+ "eventsource-parser": "^1.1.1",
99
101
  "immer": "^10.0.3",
100
102
  "lodash": "^4.17.21",
101
103
  "nanoid": "^3.3.7",
@@ -121,7 +123,7 @@
121
123
  "react-router-dom": "^6.16.0"
122
124
  },
123
125
  "devDependencies": {
124
- "@arcblock/ux": "^2.9.25",
126
+ "@arcblock/ux": "^2.9.26",
125
127
  "@emotion/cache": "^11.11.0",
126
128
  "@emotion/css": "^11.11.2",
127
129
  "@emotion/react": "^11.11.3",
@@ -131,7 +133,7 @@
131
133
  "@types/lodash": "^4.14.202",
132
134
  "@types/mustache": "^4.2.5",
133
135
  "@types/node-fetch": "^2.6.11",
134
- "@types/react": "^18.2.52",
136
+ "@types/react": "^18.2.54",
135
137
  "axios": "^1.6.7",
136
138
  "npm-run-all": "^4.1.5",
137
139
  "react": "^18.2.0",