@blocklet/pages-kit 0.2.195 → 0.2.197

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.getComponents = void 0;
13
+ const component_1 = require("@blocklet/sdk/lib/component");
14
+ function getComponents({ mode, name } = {}) {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ return (0, component_1.call)({
17
+ name: 'pages-kit',
18
+ method: 'GET',
19
+ path: '/api/components',
20
+ params: { name, mode },
21
+ }).then((res) => res.data);
22
+ });
23
+ }
24
+ exports.getComponents = getComponents;
@@ -1,2 +1,17 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./pages-kit"), exports);
@@ -83,9 +83,18 @@ const defineCustomElements = (win) => {
83
83
  throw new Error('missing required component config');
84
84
  let script;
85
85
  let current = component;
86
- const properties = Object.fromEntries(Object.entries(parameters !== null && parameters !== void 0 ? parameters : {}).map(([id, { value }]) => { var _a, _b; return [(_b = (_a = component.properties) === null || _a === void 0 ? void 0 : _a[id]) === null || _b === void 0 ? void 0 : _b.data.name, value]; }));
86
+ const properties = Object.fromEntries(Object.entries(parameters !== null && parameters !== void 0 ? parameters : {}).map(([id, { value }]) => {
87
+ var _a, _b;
88
+ const property = (_b = (_a = component.properties) === null || _a === void 0 ? void 0 : _a[id]) === null || _b === void 0 ? void 0 : _b.data;
89
+ if (!property)
90
+ return [];
91
+ return [property.name, parsePropertyValue(property.type, value)];
92
+ }));
87
93
  while (current) {
88
- mergeProperties(properties, Object.fromEntries(Object.values((_a = current.properties) !== null && _a !== void 0 ? _a : {}).map(({ data }) => [data.name, data.defaultValue])));
94
+ mergeProperties(properties, Object.fromEntries(Object.values((_a = current.properties) !== null && _a !== void 0 ? _a : {}).map(({ data }) => [
95
+ data.name,
96
+ parsePropertyValue(data.type, data.defaultValue),
97
+ ])));
89
98
  if (((_b = current.renderer) === null || _b === void 0 ? void 0 : _b.type) === 'web-component') {
90
99
  script = (_c = current.renderer) === null || _c === void 0 ? void 0 : _c.script;
91
100
  break;
@@ -95,10 +104,10 @@ const defineCustomElements = (win) => {
95
104
  .component;
96
105
  mergeProperties(properties, Object.fromEntries(Object.entries((_e = current.renderer.properties) !== null && _e !== void 0 ? _e : {}).map(([id, { value }]) => {
97
106
  var _a, _b;
98
- return [
99
- (_b = (_a = c === null || c === void 0 ? void 0 : c.properties) === null || _a === void 0 ? void 0 : _a[id]) === null || _b === void 0 ? void 0 : _b.data.name,
100
- value,
101
- ];
107
+ const property = (_b = (_a = c === null || c === void 0 ? void 0 : c.properties) === null || _a === void 0 ? void 0 : _a[id]) === null || _b === void 0 ? void 0 : _b.data;
108
+ if (!property)
109
+ return [];
110
+ return [property.name, parsePropertyValue(property.type, value)];
102
111
  })));
103
112
  current = c;
104
113
  }
@@ -162,3 +171,15 @@ function mergeProperties(properties, newProperties) {
162
171
  }
163
172
  return properties;
164
173
  }
174
+ function parsePropertyValue(type, value) {
175
+ if (type === 'json') {
176
+ try {
177
+ return JSON.parse(value);
178
+ }
179
+ catch (error) {
180
+ console.error('parse json value error', error);
181
+ return undefined;
182
+ }
183
+ }
184
+ return value;
185
+ }
@@ -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 { call } from '@blocklet/sdk/lib/component';
11
+ export function getComponents({ mode, name } = {}) {
12
+ return __awaiter(this, void 0, void 0, function* () {
13
+ return call({
14
+ name: 'pages-kit',
15
+ method: 'GET',
16
+ path: '/api/components',
17
+ params: { name, mode },
18
+ }).then((res) => res.data);
19
+ });
20
+ }
@@ -1 +1 @@
1
- export {};
1
+ export * from './pages-kit';
@@ -55,9 +55,18 @@ const defineCustomElements = (win) => {
55
55
  throw new Error('missing required component config');
56
56
  let script;
57
57
  let current = component;
58
- const properties = Object.fromEntries(Object.entries(parameters !== null && parameters !== void 0 ? parameters : {}).map(([id, { value }]) => { var _a, _b; return [(_b = (_a = component.properties) === null || _a === void 0 ? void 0 : _a[id]) === null || _b === void 0 ? void 0 : _b.data.name, value]; }));
58
+ const properties = Object.fromEntries(Object.entries(parameters !== null && parameters !== void 0 ? parameters : {}).map(([id, { value }]) => {
59
+ var _a, _b;
60
+ const property = (_b = (_a = component.properties) === null || _a === void 0 ? void 0 : _a[id]) === null || _b === void 0 ? void 0 : _b.data;
61
+ if (!property)
62
+ return [];
63
+ return [property.name, parsePropertyValue(property.type, value)];
64
+ }));
59
65
  while (current) {
60
- mergeProperties(properties, Object.fromEntries(Object.values((_a = current.properties) !== null && _a !== void 0 ? _a : {}).map(({ data }) => [data.name, data.defaultValue])));
66
+ mergeProperties(properties, Object.fromEntries(Object.values((_a = current.properties) !== null && _a !== void 0 ? _a : {}).map(({ data }) => [
67
+ data.name,
68
+ parsePropertyValue(data.type, data.defaultValue),
69
+ ])));
61
70
  if (((_b = current.renderer) === null || _b === void 0 ? void 0 : _b.type) === 'web-component') {
62
71
  script = (_c = current.renderer) === null || _c === void 0 ? void 0 : _c.script;
63
72
  break;
@@ -67,10 +76,10 @@ const defineCustomElements = (win) => {
67
76
  .component;
68
77
  mergeProperties(properties, Object.fromEntries(Object.entries((_e = current.renderer.properties) !== null && _e !== void 0 ? _e : {}).map(([id, { value }]) => {
69
78
  var _a, _b;
70
- return [
71
- (_b = (_a = c === null || c === void 0 ? void 0 : c.properties) === null || _a === void 0 ? void 0 : _a[id]) === null || _b === void 0 ? void 0 : _b.data.name,
72
- value,
73
- ];
79
+ const property = (_b = (_a = c === null || c === void 0 ? void 0 : c.properties) === null || _a === void 0 ? void 0 : _a[id]) === null || _b === void 0 ? void 0 : _b.data;
80
+ if (!property)
81
+ return [];
82
+ return [property.name, parsePropertyValue(property.type, value)];
74
83
  })));
75
84
  current = c;
76
85
  }
@@ -133,3 +142,15 @@ function mergeProperties(properties, newProperties) {
133
142
  }
134
143
  return properties;
135
144
  }
145
+ function parsePropertyValue(type, value) {
146
+ if (type === 'json') {
147
+ try {
148
+ return JSON.parse(value);
149
+ }
150
+ catch (error) {
151
+ console.error('parse json value error', error);
152
+ return undefined;
153
+ }
154
+ }
155
+ return value;
156
+ }
@@ -0,0 +1,7 @@
1
+ import { CustomComponent, StateMode } from '../types';
2
+ export declare function getComponents({ mode, name }?: {
3
+ mode?: StateMode;
4
+ name?: string;
5
+ }): Promise<{
6
+ components: CustomComponent[];
7
+ }>;
@@ -1 +1 @@
1
- export {};
1
+ export * from './pages-kit';
@@ -1,8 +1,7 @@
1
- import { CustomComponentType } from '../types';
2
- export type Mode = 'draft' | 'staging' | 'production';
1
+ import { CustomComponent, StateMode } from '../types';
3
2
  export declare function getComponents({ mode, name }?: {
4
- mode?: Mode;
3
+ mode?: StateMode;
5
4
  name?: string;
6
5
  }): Promise<{
7
- components: CustomComponentType;
6
+ components: CustomComponent[];
8
7
  }>;
@@ -1,8 +1,8 @@
1
- import { CustomComponentType } from '../../types';
1
+ import { CustomComponent } from '../../types';
2
2
  export default function CustomComponentRenderer({ id, componentId, components, properties, }: {
3
3
  id: string;
4
4
  componentId: string;
5
- components?: CustomComponentType[];
5
+ components?: CustomComponent[];
6
6
  properties?: {
7
7
  [key: string]: {
8
8
  value: any;
@@ -1,4 +1,5 @@
1
- export type CustomComponentType = {
1
+ export type StateMode = 'draft' | 'staging' | 'production';
2
+ export type CustomComponent = {
2
3
  id: string;
3
4
  createdAt: string;
4
5
  updatedAt: string;
@@ -24,7 +25,7 @@ export type CustomComponentType = {
24
25
  data: {
25
26
  id: string;
26
27
  name?: string;
27
- type?: 'string' | 'number' | 'boolean' | 'custom-component';
28
+ type?: 'string' | 'number' | 'boolean' | 'json' | 'custom-component';
28
29
  defaultValue?: any;
29
30
  };
30
31
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/pages-kit",
3
- "version": "0.2.195",
3
+ "version": "0.2.197",
4
4
  "description": "Pages Kit components and utils",
5
5
  "publishConfig": {
6
6
  "access": "public"