@blocklet/pages-kit 0.2.196 → 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.
@@ -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
+ }
@@ -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
+ }
@@ -25,7 +25,7 @@ export type CustomComponent = {
25
25
  data: {
26
26
  id: string;
27
27
  name?: string;
28
- type?: 'string' | 'number' | 'boolean' | 'custom-component';
28
+ type?: 'string' | 'number' | 'boolean' | 'json' | 'custom-component';
29
29
  defaultValue?: any;
30
30
  };
31
31
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/pages-kit",
3
- "version": "0.2.196",
3
+ "version": "0.2.197",
4
4
  "description": "Pages Kit components and utils",
5
5
  "publishConfig": {
6
6
  "access": "public"