@webstudio-is/sdk 0.167.0 → 0.173.0
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/lib/index.js +157 -119
- package/lib/types/index.d.ts +0 -1
- package/lib/types/instances-utils.d.ts +3 -35
- package/lib/types/jsx.d.ts +151 -0
- package/lib/types/page-meta-generator.d.ts +4 -3
- package/lib/types/resource-loader.d.ts +10 -1
- package/lib/types/resources-generator.d.ts +13 -1
- package/lib/types/schema/pages.d.ts +4 -4
- package/lib/types/schema/props.d.ts +42 -0
- package/lib/types/schema/resources.d.ts +6 -6
- package/lib/types/schema/styles.d.ts +1836 -9833
- package/lib/types/schema/webstudio.d.ts +625 -946
- package/lib/types/scope.d.ts +1 -1
- package/lib/types/testing.d.ts +1 -0
- package/package.json +13 -10
- package/lib/types/forms-generator.d.ts +0 -84
- /package/lib/types/{forms-generator.test.d.ts → jsx.test.d.ts} +0 -0
package/lib/index.js
CHANGED
|
@@ -322,6 +322,12 @@ var Prop = z6.union([
|
|
|
322
322
|
// data source id
|
|
323
323
|
value: z6.string()
|
|
324
324
|
}),
|
|
325
|
+
z6.object({
|
|
326
|
+
...baseProp,
|
|
327
|
+
type: z6.literal("resource"),
|
|
328
|
+
// resource id
|
|
329
|
+
value: z6.string()
|
|
330
|
+
}),
|
|
325
331
|
z6.object({
|
|
326
332
|
...baseProp,
|
|
327
333
|
type: z6.literal("expression"),
|
|
@@ -487,8 +493,9 @@ var lintExpression = ({
|
|
|
487
493
|
const addError = (message) => {
|
|
488
494
|
return (node) => {
|
|
489
495
|
diagnostics.push({
|
|
490
|
-
|
|
491
|
-
|
|
496
|
+
// tune error position after wrapping expression with parentheses
|
|
497
|
+
from: node.start - 1,
|
|
498
|
+
to: node.end - 1,
|
|
492
499
|
severity: "error",
|
|
493
500
|
message
|
|
494
501
|
});
|
|
@@ -504,7 +511,7 @@ var lintExpression = ({
|
|
|
504
511
|
return diagnostics;
|
|
505
512
|
}
|
|
506
513
|
try {
|
|
507
|
-
const root = parseExpressionAt(expression
|
|
514
|
+
const root = parseExpressionAt(`(${expression})`, 0, {
|
|
508
515
|
ecmaVersion: "latest",
|
|
509
516
|
// support parsing import to forbid explicitly
|
|
510
517
|
sourceType: "module"
|
|
@@ -569,10 +576,13 @@ var lintExpression = ({
|
|
|
569
576
|
} catch (error) {
|
|
570
577
|
const castedError = error;
|
|
571
578
|
diagnostics.push({
|
|
572
|
-
|
|
573
|
-
|
|
579
|
+
// tune error position after wrapping expression with parentheses
|
|
580
|
+
from: castedError.pos - 1,
|
|
581
|
+
to: castedError.pos - 1,
|
|
574
582
|
severity: "error",
|
|
575
|
-
|
|
583
|
+
// trim auto generated error location
|
|
584
|
+
// to not conflict with tuned position
|
|
585
|
+
message: castedError.message.replaceAll(/\s+\(\d+:\d+\)$/g, "")
|
|
576
586
|
});
|
|
577
587
|
}
|
|
578
588
|
return diagnostics;
|
|
@@ -823,7 +833,7 @@ var getStaticSiteMapXml = (pages, updatedAt) => {
|
|
|
823
833
|
};
|
|
824
834
|
|
|
825
835
|
// src/scope.ts
|
|
826
|
-
var
|
|
836
|
+
var normalizeJsName = (name) => {
|
|
827
837
|
name = name.replaceAll(/[^\w$]/g, "");
|
|
828
838
|
if (name.length === 0) {
|
|
829
839
|
return "_";
|
|
@@ -833,7 +843,7 @@ var normalizeName = (name) => {
|
|
|
833
843
|
}
|
|
834
844
|
return name;
|
|
835
845
|
};
|
|
836
|
-
var createScope = (occupiedIdentifiers = []) => {
|
|
846
|
+
var createScope = (occupiedIdentifiers = [], normalizeName = normalizeJsName, separator = "_") => {
|
|
837
847
|
const freeIndexByPreferredName = /* @__PURE__ */ new Map();
|
|
838
848
|
const scopedNameByIdMap = /* @__PURE__ */ new Map();
|
|
839
849
|
for (const identifier of occupiedIdentifiers) {
|
|
@@ -849,7 +859,7 @@ var createScope = (occupiedIdentifiers = []) => {
|
|
|
849
859
|
freeIndexByPreferredName.set(preferredName, (index ?? 0) + 1);
|
|
850
860
|
let scopedName = preferredName;
|
|
851
861
|
if (index !== void 0) {
|
|
852
|
-
scopedName = `${preferredName}
|
|
862
|
+
scopedName = `${preferredName}${separator}${index}`;
|
|
853
863
|
}
|
|
854
864
|
scopedNameByIdMap.set(id, scopedName);
|
|
855
865
|
return scopedName;
|
|
@@ -860,8 +870,8 @@ var createScope = (occupiedIdentifiers = []) => {
|
|
|
860
870
|
};
|
|
861
871
|
|
|
862
872
|
// src/resource-loader.ts
|
|
863
|
-
var loadResource = async (customFetch,
|
|
864
|
-
const { url, method, headers, body } =
|
|
873
|
+
var loadResource = async (customFetch, resourceRequest) => {
|
|
874
|
+
const { url, method, headers, body } = resourceRequest;
|
|
865
875
|
const requestHeaders = new Headers(
|
|
866
876
|
headers.map(({ name, value }) => [name, value])
|
|
867
877
|
);
|
|
@@ -881,12 +891,13 @@ var loadResource = async (customFetch, resourceData) => {
|
|
|
881
891
|
const response = await customFetch(url.trim(), requestInit);
|
|
882
892
|
let data;
|
|
883
893
|
if (response.ok && // accept json by default and when specified explicitly
|
|
884
|
-
(
|
|
894
|
+
(response.headers.has("content-type") === false || response.headers.get("content-type")?.includes("application/json"))) {
|
|
885
895
|
data = await response.json();
|
|
886
896
|
} else {
|
|
887
897
|
data = await response.text();
|
|
888
898
|
}
|
|
889
899
|
return {
|
|
900
|
+
ok: response.ok,
|
|
890
901
|
data,
|
|
891
902
|
status: response.status,
|
|
892
903
|
statusText: response.statusText
|
|
@@ -894,108 +905,87 @@ var loadResource = async (customFetch, resourceData) => {
|
|
|
894
905
|
} catch (error) {
|
|
895
906
|
const message = error.message;
|
|
896
907
|
return {
|
|
908
|
+
ok: false,
|
|
897
909
|
data: void 0,
|
|
898
910
|
status: 500,
|
|
899
911
|
statusText: message
|
|
900
912
|
};
|
|
901
913
|
}
|
|
902
914
|
};
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
properties = {};
|
|
913
|
-
}
|
|
914
|
-
properties[prop.name] = prop.value;
|
|
915
|
-
formsProperties.set(prop.instanceId, properties);
|
|
916
|
-
}
|
|
917
|
-
}
|
|
918
|
-
}
|
|
919
|
-
const entriesString = JSON.stringify(Array.from(formsProperties.entries()));
|
|
920
|
-
let generated = "";
|
|
921
|
-
generated += `type FormProperties = { method?: string, action?: string }
|
|
922
|
-
`;
|
|
923
|
-
generated += `export const formsProperties = new Map<string, FormProperties>(${entriesString})
|
|
924
|
-
`;
|
|
925
|
-
return generated;
|
|
915
|
+
var loadResources = async (customFetch, requests) => {
|
|
916
|
+
return Object.fromEntries(
|
|
917
|
+
await Promise.all(
|
|
918
|
+
Array.from(
|
|
919
|
+
requests,
|
|
920
|
+
async ([name, request]) => [name, await loadResource(customFetch, request)]
|
|
921
|
+
)
|
|
922
|
+
)
|
|
923
|
+
);
|
|
926
924
|
};
|
|
927
925
|
|
|
928
926
|
// src/resources-generator.ts
|
|
929
|
-
var
|
|
927
|
+
var generateResources = ({
|
|
930
928
|
scope,
|
|
931
929
|
page,
|
|
932
930
|
dataSources,
|
|
931
|
+
props,
|
|
933
932
|
resources
|
|
934
933
|
}) => {
|
|
935
|
-
let generatedOutput = "";
|
|
936
|
-
let generatedLoaders = "";
|
|
937
|
-
let hasResources = false;
|
|
938
934
|
const usedDataSources = /* @__PURE__ */ new Map();
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
}
|
|
945
|
-
hasResources = true;
|
|
946
|
-
const resourceName = scope.getName(resource.id, dataSource.name);
|
|
947
|
-
generatedOutput += `${resourceName},
|
|
935
|
+
let generatedRequests = "";
|
|
936
|
+
for (const resource of resources.values()) {
|
|
937
|
+
let generatedRequest = "";
|
|
938
|
+
const resourceName = scope.getName(resource.id, resource.name);
|
|
939
|
+
generatedRequest += ` const ${resourceName}: ResourceRequest = {
|
|
948
940
|
`;
|
|
949
|
-
|
|
941
|
+
generatedRequest += ` id: "${resource.id}",
|
|
950
942
|
`;
|
|
951
|
-
|
|
943
|
+
generatedRequest += ` name: ${JSON.stringify(resource.name)},
|
|
952
944
|
`;
|
|
953
|
-
|
|
945
|
+
const url = generateExpression({
|
|
946
|
+
expression: resource.url,
|
|
947
|
+
dataSources,
|
|
948
|
+
usedDataSources,
|
|
949
|
+
scope
|
|
950
|
+
});
|
|
951
|
+
generatedRequest += ` url: ${url},
|
|
954
952
|
`;
|
|
955
|
-
|
|
956
|
-
|
|
953
|
+
generatedRequest += ` method: "${resource.method}",
|
|
954
|
+
`;
|
|
955
|
+
generatedRequest += ` headers: [
|
|
956
|
+
`;
|
|
957
|
+
for (const header of resource.headers) {
|
|
958
|
+
const value = generateExpression({
|
|
959
|
+
expression: header.value,
|
|
957
960
|
dataSources,
|
|
958
961
|
usedDataSources,
|
|
959
962
|
scope
|
|
960
963
|
});
|
|
961
|
-
|
|
962
|
-
`;
|
|
963
|
-
generatedLoaders += `method: "${resource.method}",
|
|
964
|
-
`;
|
|
965
|
-
generatedLoaders += `headers: [
|
|
964
|
+
generatedRequest += ` { name: "${header.name}", value: ${value} },
|
|
966
965
|
`;
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
expression: header.value,
|
|
970
|
-
dataSources,
|
|
971
|
-
usedDataSources,
|
|
972
|
-
scope
|
|
973
|
-
});
|
|
974
|
-
generatedLoaders += `{ name: "${header.name}", value: ${value} },
|
|
975
|
-
`;
|
|
976
|
-
}
|
|
977
|
-
generatedLoaders += `],
|
|
978
|
-
`;
|
|
979
|
-
if (resource.body !== void 0 && resource.body.length > 0) {
|
|
980
|
-
const body = generateExpression({
|
|
981
|
-
expression: resource.body,
|
|
982
|
-
dataSources,
|
|
983
|
-
usedDataSources,
|
|
984
|
-
scope
|
|
985
|
-
});
|
|
986
|
-
generatedLoaders += `body: ${body},
|
|
966
|
+
}
|
|
967
|
+
generatedRequest += ` ],
|
|
987
968
|
`;
|
|
988
|
-
|
|
989
|
-
|
|
969
|
+
if (resource.body !== void 0 && resource.body.length > 0) {
|
|
970
|
+
const body = generateExpression({
|
|
971
|
+
expression: resource.body,
|
|
972
|
+
dataSources,
|
|
973
|
+
usedDataSources,
|
|
974
|
+
scope
|
|
975
|
+
});
|
|
976
|
+
generatedRequest += ` body: ${body},
|
|
990
977
|
`;
|
|
991
978
|
}
|
|
979
|
+
generatedRequest += ` }
|
|
980
|
+
`;
|
|
981
|
+
generatedRequests += generatedRequest;
|
|
992
982
|
}
|
|
993
983
|
let generatedVariables = "";
|
|
994
984
|
for (const dataSource of usedDataSources.values()) {
|
|
995
985
|
if (dataSource.type === "variable") {
|
|
996
986
|
const name = scope.getName(dataSource.id, dataSource.name);
|
|
997
987
|
const value = JSON.stringify(dataSource.value.value);
|
|
998
|
-
generatedVariables += `let ${name} = ${value}
|
|
988
|
+
generatedVariables += ` let ${name} = ${value}
|
|
999
989
|
`;
|
|
1000
990
|
}
|
|
1001
991
|
if (dataSource.type === "parameter") {
|
|
@@ -1003,61 +993,108 @@ var generateResourcesLoader = ({
|
|
|
1003
993
|
continue;
|
|
1004
994
|
}
|
|
1005
995
|
const name = scope.getName(dataSource.id, dataSource.name);
|
|
1006
|
-
generatedVariables += `const ${name} = _props.system
|
|
996
|
+
generatedVariables += ` const ${name} = _props.system
|
|
1007
997
|
`;
|
|
1008
998
|
}
|
|
1009
999
|
}
|
|
1010
1000
|
let generated = "";
|
|
1011
|
-
generated += `import {
|
|
1001
|
+
generated += `import type { System, ResourceRequest } from "@webstudio-is/sdk";
|
|
1012
1002
|
`;
|
|
1013
|
-
|
|
1014
|
-
generated += `import { sitemap } from "./$resources.sitemap.xml";
|
|
1015
|
-
`;
|
|
1016
|
-
}
|
|
1017
|
-
generated += `export const loadResources = async (_props: { system: System }) => {
|
|
1003
|
+
generated += `export const getResources = (_props: { system: System }) => {
|
|
1018
1004
|
`;
|
|
1019
1005
|
generated += generatedVariables;
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
const customFetch: typeof fetch = (input, init) => {
|
|
1023
|
-
if (typeof input !== "string") {
|
|
1024
|
-
return fetch(input, init);
|
|
1025
|
-
}
|
|
1026
|
-
|
|
1027
|
-
if (isLocalResource(input, "sitemap.xml")) {
|
|
1028
|
-
// @todo: dynamic import sitemap ???
|
|
1029
|
-
const response = new Response(JSON.stringify(sitemap));
|
|
1030
|
-
response.headers.set('content-type', 'application/json; charset=utf-8');
|
|
1031
|
-
return Promise.resolve(response);
|
|
1032
|
-
}
|
|
1033
|
-
|
|
1034
|
-
return fetch(input, init);
|
|
1035
|
-
};
|
|
1036
|
-
`;
|
|
1037
|
-
generated += `const [
|
|
1006
|
+
generated += generatedRequests;
|
|
1007
|
+
generated += ` const _data = new Map<string, ResourceRequest>([
|
|
1038
1008
|
`;
|
|
1039
|
-
|
|
1040
|
-
|
|
1009
|
+
for (const dataSource of dataSources.values()) {
|
|
1010
|
+
if (dataSource.type === "resource") {
|
|
1011
|
+
const name = scope.getName(dataSource.resourceId, dataSource.name);
|
|
1012
|
+
generated += ` ["${name}", ${name}],
|
|
1041
1013
|
`;
|
|
1042
|
-
|
|
1043
|
-
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
generated += ` ])
|
|
1017
|
+
`;
|
|
1018
|
+
generated += ` const _action = new Map<string, ResourceRequest>([
|
|
1019
|
+
`;
|
|
1020
|
+
for (const prop of props.values()) {
|
|
1021
|
+
if (prop.type === "resource") {
|
|
1022
|
+
const name = scope.getName(prop.value, prop.name);
|
|
1023
|
+
generated += ` ["${name}", ${name}],
|
|
1044
1024
|
`;
|
|
1025
|
+
}
|
|
1045
1026
|
}
|
|
1046
|
-
generated += `
|
|
1027
|
+
generated += ` ])
|
|
1047
1028
|
`;
|
|
1048
|
-
generated +=
|
|
1049
|
-
generated += `} as Record<string, unknown>
|
|
1029
|
+
generated += ` return { data: _data, action: _action }
|
|
1050
1030
|
`;
|
|
1051
1031
|
generated += `}
|
|
1052
1032
|
`;
|
|
1053
1033
|
return generated;
|
|
1054
1034
|
};
|
|
1035
|
+
var getMethod = (value) => {
|
|
1036
|
+
switch (value?.toLowerCase()) {
|
|
1037
|
+
case "get":
|
|
1038
|
+
return "get";
|
|
1039
|
+
case "delete":
|
|
1040
|
+
return "delete";
|
|
1041
|
+
case "put":
|
|
1042
|
+
return "put";
|
|
1043
|
+
default:
|
|
1044
|
+
return "post";
|
|
1045
|
+
}
|
|
1046
|
+
};
|
|
1047
|
+
var replaceFormActionsWithResources = ({
|
|
1048
|
+
props,
|
|
1049
|
+
instances,
|
|
1050
|
+
resources
|
|
1051
|
+
}) => {
|
|
1052
|
+
const formProps = /* @__PURE__ */ new Map();
|
|
1053
|
+
for (const prop of props.values()) {
|
|
1054
|
+
if (prop.name === "method" && prop.type === "string" && instances.get(prop.instanceId)?.component === "Form") {
|
|
1055
|
+
let data = formProps.get(prop.instanceId);
|
|
1056
|
+
if (data === void 0) {
|
|
1057
|
+
data = {};
|
|
1058
|
+
formProps.set(prop.instanceId, data);
|
|
1059
|
+
}
|
|
1060
|
+
data.method = prop.value;
|
|
1061
|
+
props.delete(prop.id);
|
|
1062
|
+
}
|
|
1063
|
+
if (prop.name === "action" && prop.type === "string" && instances.get(prop.instanceId)?.component === "Form") {
|
|
1064
|
+
let data = formProps.get(prop.instanceId);
|
|
1065
|
+
if (data === void 0) {
|
|
1066
|
+
data = {};
|
|
1067
|
+
formProps.set(prop.instanceId, data);
|
|
1068
|
+
}
|
|
1069
|
+
data.action = prop.value;
|
|
1070
|
+
props.set(prop.id, {
|
|
1071
|
+
id: prop.id,
|
|
1072
|
+
instanceId: prop.instanceId,
|
|
1073
|
+
name: prop.name,
|
|
1074
|
+
type: "resource",
|
|
1075
|
+
value: prop.instanceId
|
|
1076
|
+
});
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
for (const [instanceId, { action, method }] of formProps) {
|
|
1080
|
+
if (action) {
|
|
1081
|
+
resources.set(instanceId, {
|
|
1082
|
+
id: instanceId,
|
|
1083
|
+
name: "action",
|
|
1084
|
+
method: getMethod(method),
|
|
1085
|
+
url: JSON.stringify(action),
|
|
1086
|
+
headers: []
|
|
1087
|
+
});
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
};
|
|
1055
1091
|
|
|
1056
1092
|
// src/page-meta-generator.ts
|
|
1057
1093
|
var generatePageMeta = ({
|
|
1058
1094
|
globalScope,
|
|
1059
1095
|
page,
|
|
1060
|
-
dataSources
|
|
1096
|
+
dataSources,
|
|
1097
|
+
assets
|
|
1061
1098
|
}) => {
|
|
1062
1099
|
const localScope = createScope(["system", "resources"]);
|
|
1063
1100
|
const usedDataSources = /* @__PURE__ */ new Map();
|
|
@@ -1085,8 +1122,8 @@ var generatePageMeta = ({
|
|
|
1085
1122
|
usedDataSources,
|
|
1086
1123
|
scope: localScope
|
|
1087
1124
|
});
|
|
1088
|
-
const
|
|
1089
|
-
page.meta.socialImageAssetId
|
|
1125
|
+
const socialImageAssetNameExpression = JSON.stringify(
|
|
1126
|
+
page.meta.socialImageAssetId ? assets.get(page.meta.socialImageAssetId)?.name : void 0
|
|
1090
1127
|
);
|
|
1091
1128
|
const socialImageUrlExpression = generateExpression({
|
|
1092
1129
|
expression: page.meta.socialImageUrl ?? "undefined",
|
|
@@ -1182,7 +1219,7 @@ var generatePageMeta = ({
|
|
|
1182
1219
|
`;
|
|
1183
1220
|
generated += ` language: ${languageExpression},
|
|
1184
1221
|
`;
|
|
1185
|
-
generated += `
|
|
1222
|
+
generated += ` socialImageAssetName: ${socialImageAssetNameExpression},
|
|
1186
1223
|
`;
|
|
1187
1224
|
generated += ` socialImageUrl: ${socialImageUrlExpression},
|
|
1188
1225
|
`;
|
|
@@ -1249,10 +1286,9 @@ export {
|
|
|
1249
1286
|
findTreeInstanceIds,
|
|
1250
1287
|
findTreeInstanceIdsExcludingSlotDescendants,
|
|
1251
1288
|
generateExpression,
|
|
1252
|
-
generateFormsProperties,
|
|
1253
1289
|
generateObjectExpression,
|
|
1254
1290
|
generatePageMeta,
|
|
1255
|
-
|
|
1291
|
+
generateResources,
|
|
1256
1292
|
getExpressionIdentifiers,
|
|
1257
1293
|
getPagePath,
|
|
1258
1294
|
getStaticSiteMapXml,
|
|
@@ -1264,9 +1300,11 @@ export {
|
|
|
1264
1300
|
isRoot,
|
|
1265
1301
|
lintExpression,
|
|
1266
1302
|
loadResource,
|
|
1303
|
+
loadResources,
|
|
1267
1304
|
matchPathnameParams,
|
|
1268
1305
|
parseComponentName,
|
|
1269
1306
|
parseObjectExpression,
|
|
1307
|
+
replaceFormActionsWithResources,
|
|
1270
1308
|
sitemapResourceUrl,
|
|
1271
1309
|
transpileExpression
|
|
1272
1310
|
};
|
package/lib/types/index.d.ts
CHANGED
|
@@ -15,7 +15,6 @@ export * from "./page-utils";
|
|
|
15
15
|
export * from "./scope";
|
|
16
16
|
export * from "./resource-loader";
|
|
17
17
|
export * from "./expression";
|
|
18
|
-
export * from "./forms-generator";
|
|
19
18
|
export * from "./resources-generator";
|
|
20
19
|
export * from "./page-meta-generator";
|
|
21
20
|
export * from "./url-pattern";
|
|
@@ -1,36 +1,4 @@
|
|
|
1
|
-
import type { Instance } from "./schema/instances";
|
|
2
|
-
export declare const findTreeInstanceIds: (instances:
|
|
3
|
-
|
|
4
|
-
id: string;
|
|
5
|
-
children: ({
|
|
6
|
-
value: string;
|
|
7
|
-
type: "text";
|
|
8
|
-
placeholder?: boolean | undefined;
|
|
9
|
-
} | {
|
|
10
|
-
value: string;
|
|
11
|
-
type: "id";
|
|
12
|
-
} | {
|
|
13
|
-
value: string;
|
|
14
|
-
type: "expression";
|
|
15
|
-
})[];
|
|
16
|
-
component: string;
|
|
17
|
-
label?: string | undefined;
|
|
18
|
-
}>, rootInstanceId: Instance["id"]) => Set<string>;
|
|
19
|
-
export declare const findTreeInstanceIdsExcludingSlotDescendants: (instances: Map<string, {
|
|
20
|
-
type: "instance";
|
|
21
|
-
id: string;
|
|
22
|
-
children: ({
|
|
23
|
-
value: string;
|
|
24
|
-
type: "text";
|
|
25
|
-
placeholder?: boolean | undefined;
|
|
26
|
-
} | {
|
|
27
|
-
value: string;
|
|
28
|
-
type: "id";
|
|
29
|
-
} | {
|
|
30
|
-
value: string;
|
|
31
|
-
type: "expression";
|
|
32
|
-
})[];
|
|
33
|
-
component: string;
|
|
34
|
-
label?: string | undefined;
|
|
35
|
-
}>, rootInstanceId: Instance["id"]) => Set<string>;
|
|
1
|
+
import type { Instance, Instances } from "./schema/instances";
|
|
2
|
+
export declare const findTreeInstanceIds: (instances: Instances, rootInstanceId: Instance["id"]) => Set<string>;
|
|
3
|
+
export declare const findTreeInstanceIdsExcludingSlotDescendants: (instances: Instances, rootInstanceId: Instance["id"]) => Set<string>;
|
|
36
4
|
export declare const parseComponentName: (componentName: string) => readonly [string | undefined, string];
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
export declare class ExpressionValue {
|
|
3
|
+
value: string;
|
|
4
|
+
constructor(expression: string);
|
|
5
|
+
}
|
|
6
|
+
export declare class ParameterValue {
|
|
7
|
+
value: string;
|
|
8
|
+
constructor(dataSourceID: string);
|
|
9
|
+
}
|
|
10
|
+
export declare class ResourceValue {
|
|
11
|
+
value: string;
|
|
12
|
+
constructor(resourceId: string);
|
|
13
|
+
}
|
|
14
|
+
export declare class ActionValue {
|
|
15
|
+
value: {
|
|
16
|
+
type: "execute";
|
|
17
|
+
args: string[];
|
|
18
|
+
code: string;
|
|
19
|
+
};
|
|
20
|
+
constructor(args: string[], code: string);
|
|
21
|
+
}
|
|
22
|
+
export declare class AssetValue {
|
|
23
|
+
value: string;
|
|
24
|
+
constructor(assetId: string);
|
|
25
|
+
}
|
|
26
|
+
export declare class PageValue {
|
|
27
|
+
value: string | {
|
|
28
|
+
pageId: string;
|
|
29
|
+
instanceId: string;
|
|
30
|
+
};
|
|
31
|
+
constructor(pageId: string, instanceId?: string);
|
|
32
|
+
}
|
|
33
|
+
export declare const renderJsx: (root: JSX.Element) => {
|
|
34
|
+
instances: Map<string, {
|
|
35
|
+
type: "instance";
|
|
36
|
+
id: string;
|
|
37
|
+
children: ({
|
|
38
|
+
value: string;
|
|
39
|
+
type: "text";
|
|
40
|
+
placeholder?: boolean | undefined;
|
|
41
|
+
} | {
|
|
42
|
+
value: string;
|
|
43
|
+
type: "id";
|
|
44
|
+
} | {
|
|
45
|
+
value: string;
|
|
46
|
+
type: "expression";
|
|
47
|
+
})[];
|
|
48
|
+
component: string;
|
|
49
|
+
label?: string | undefined;
|
|
50
|
+
}>;
|
|
51
|
+
props: Map<string, {
|
|
52
|
+
value: number;
|
|
53
|
+
type: "number";
|
|
54
|
+
id: string;
|
|
55
|
+
name: string;
|
|
56
|
+
instanceId: string;
|
|
57
|
+
required?: boolean | undefined;
|
|
58
|
+
} | {
|
|
59
|
+
value: string;
|
|
60
|
+
type: "string";
|
|
61
|
+
id: string;
|
|
62
|
+
name: string;
|
|
63
|
+
instanceId: string;
|
|
64
|
+
required?: boolean | undefined;
|
|
65
|
+
} | {
|
|
66
|
+
value: boolean;
|
|
67
|
+
type: "boolean";
|
|
68
|
+
id: string;
|
|
69
|
+
name: string;
|
|
70
|
+
instanceId: string;
|
|
71
|
+
required?: boolean | undefined;
|
|
72
|
+
} | {
|
|
73
|
+
type: "json";
|
|
74
|
+
id: string;
|
|
75
|
+
name: string;
|
|
76
|
+
instanceId: string;
|
|
77
|
+
value?: unknown;
|
|
78
|
+
required?: boolean | undefined;
|
|
79
|
+
} | {
|
|
80
|
+
value: string;
|
|
81
|
+
type: "asset";
|
|
82
|
+
id: string;
|
|
83
|
+
name: string;
|
|
84
|
+
instanceId: string;
|
|
85
|
+
required?: boolean | undefined;
|
|
86
|
+
} | {
|
|
87
|
+
value: (string | {
|
|
88
|
+
instanceId: string;
|
|
89
|
+
pageId: string;
|
|
90
|
+
}) & (string | {
|
|
91
|
+
instanceId: string;
|
|
92
|
+
pageId: string;
|
|
93
|
+
} | undefined);
|
|
94
|
+
type: "page";
|
|
95
|
+
id: string;
|
|
96
|
+
name: string;
|
|
97
|
+
instanceId: string;
|
|
98
|
+
required?: boolean | undefined;
|
|
99
|
+
} | {
|
|
100
|
+
value: string[];
|
|
101
|
+
type: "string[]";
|
|
102
|
+
id: string;
|
|
103
|
+
name: string;
|
|
104
|
+
instanceId: string;
|
|
105
|
+
required?: boolean | undefined;
|
|
106
|
+
} | {
|
|
107
|
+
value: string;
|
|
108
|
+
type: "parameter";
|
|
109
|
+
id: string;
|
|
110
|
+
name: string;
|
|
111
|
+
instanceId: string;
|
|
112
|
+
required?: boolean | undefined;
|
|
113
|
+
} | {
|
|
114
|
+
value: string;
|
|
115
|
+
type: "resource";
|
|
116
|
+
id: string;
|
|
117
|
+
name: string;
|
|
118
|
+
instanceId: string;
|
|
119
|
+
required?: boolean | undefined;
|
|
120
|
+
} | {
|
|
121
|
+
value: string;
|
|
122
|
+
type: "expression";
|
|
123
|
+
id: string;
|
|
124
|
+
name: string;
|
|
125
|
+
instanceId: string;
|
|
126
|
+
required?: boolean | undefined;
|
|
127
|
+
} | {
|
|
128
|
+
value: {
|
|
129
|
+
code: string;
|
|
130
|
+
type: "execute";
|
|
131
|
+
args: string[];
|
|
132
|
+
}[];
|
|
133
|
+
type: "action";
|
|
134
|
+
id: string;
|
|
135
|
+
name: string;
|
|
136
|
+
instanceId: string;
|
|
137
|
+
required?: boolean | undefined;
|
|
138
|
+
}>;
|
|
139
|
+
};
|
|
140
|
+
type ComponentProps = Record<string, unknown> & Record<`${string}:expression`, string> & {
|
|
141
|
+
"ws:id"?: string;
|
|
142
|
+
"ws:label"?: string;
|
|
143
|
+
children?: ReactNode;
|
|
144
|
+
};
|
|
145
|
+
type Component = {
|
|
146
|
+
displayName: string;
|
|
147
|
+
} & ((props: ComponentProps) => ReactNode);
|
|
148
|
+
export declare const createProxy: (prefix: string) => Record<string, Component>;
|
|
149
|
+
export declare const $: Record<string, Component>;
|
|
150
|
+
export declare const ws: Record<string, Component>;
|
|
151
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Asset } from "./schema/assets";
|
|
1
|
+
import type { Asset, Assets } from "./schema/assets";
|
|
2
2
|
import type { DataSources } from "./schema/data-sources";
|
|
3
3
|
import type { Page } from "./schema/pages";
|
|
4
4
|
import { type Scope } from "./scope";
|
|
@@ -7,7 +7,7 @@ export type PageMeta = {
|
|
|
7
7
|
description?: string;
|
|
8
8
|
excludePageFromSearch?: boolean;
|
|
9
9
|
language?: string;
|
|
10
|
-
|
|
10
|
+
socialImageAssetName?: Asset["name"];
|
|
11
11
|
socialImageUrl?: string;
|
|
12
12
|
status?: number;
|
|
13
13
|
redirect?: string;
|
|
@@ -16,8 +16,9 @@ export type PageMeta = {
|
|
|
16
16
|
content: string;
|
|
17
17
|
}>;
|
|
18
18
|
};
|
|
19
|
-
export declare const generatePageMeta: ({ globalScope, page, dataSources, }: {
|
|
19
|
+
export declare const generatePageMeta: ({ globalScope, page, dataSources, assets, }: {
|
|
20
20
|
globalScope: Scope;
|
|
21
21
|
page: Page;
|
|
22
22
|
dataSources: DataSources;
|
|
23
|
+
assets: Assets;
|
|
23
24
|
}) => string;
|
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import type { ResourceRequest } from "./schema/resources";
|
|
2
|
-
export declare const loadResource: (customFetch: typeof fetch,
|
|
2
|
+
export declare const loadResource: (customFetch: typeof fetch, resourceRequest: ResourceRequest) => Promise<{
|
|
3
|
+
ok: boolean;
|
|
3
4
|
data: any;
|
|
4
5
|
status: number;
|
|
5
6
|
statusText: string;
|
|
6
7
|
}>;
|
|
8
|
+
export declare const loadResources: (customFetch: typeof fetch, requests: Map<string, ResourceRequest>) => Promise<{
|
|
9
|
+
[k: string]: {
|
|
10
|
+
ok: boolean;
|
|
11
|
+
data: any;
|
|
12
|
+
status: number;
|
|
13
|
+
statusText: string;
|
|
14
|
+
};
|
|
15
|
+
}>;
|