@webstudio-is/sdk 0.275.0 → 0.276.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.
@@ -757,7 +757,7 @@ var blockMeta2 = {
757
757
  "."
758
758
  ] }),
759
759
  /* @__PURE__ */ jsxs(ws.element, { "ws:label": "Unordered List", "ws:tag": "ul", children: [
760
- /* @__PURE__ */ jsx(ws.element, { "ws:label": "List Item", "ws:tag": "li", children: "In Content mode, you can edit any direct child instances that were pre-added to the Content Block, as well as add new instances predefined in templates." }),
760
+ /* @__PURE__ */ jsx(ws.element, { "ws:label": "List Item", "ws:tag": "li", children: "In Content mode, you can edit content inside this Content Block and add new instances predefined in templates. Content outside Content Blocks is read-only." }),
761
761
  /* @__PURE__ */ jsx(ws.element, { "ws:label": "List Item", "ws:tag": "li", children: "To predefine instances for insertion in Content mode, switch to Design mode and add them to the Templates container." }),
762
762
  /* @__PURE__ */ jsx(ws.element, { "ws:label": "List Item", "ws:tag": "li", children: "To insert predefined instances in Content mode, click the + button while hovering over the Content Block on the canvas and choose an instance from the list." })
763
763
  ] })
package/lib/index.js CHANGED
@@ -185,6 +185,7 @@ var projectMeta = z2.object({
185
185
  contactEmail: z2.string().optional(),
186
186
  faviconAssetId: z2.string().optional(),
187
187
  code: z2.string().optional(),
188
+ agentInstructions: z2.string().optional(),
188
189
  auth: z2.string().optional()
189
190
  });
190
191
  var projectNewRedirectPath = z2.string().min(1, "Path is required").refine((data) => {
@@ -928,7 +929,11 @@ var code = z14.object({
928
929
  ...common,
929
930
  control: z14.literal("code"),
930
931
  type: z14.literal("string"),
931
- language: z14.union([z14.literal("html"), z14.literal("markdown")]),
932
+ language: z14.union([
933
+ z14.literal("html"),
934
+ z14.literal("json"),
935
+ z14.literal("markdown")
936
+ ]),
932
937
  defaultValue: z14.string().optional()
933
938
  });
934
939
  var codeText = z14.object({
@@ -937,6 +942,12 @@ var codeText = z14.object({
937
942
  type: z14.literal("string"),
938
943
  defaultValue: z14.string().optional()
939
944
  });
945
+ var jsonCode = z14.object({
946
+ ...common,
947
+ control: z14.literal("json-code"),
948
+ type: z14.literal("string"),
949
+ defaultValue: z14.string().optional()
950
+ });
940
951
  var color = z14.object({
941
952
  ...common,
942
953
  control: z14.literal("color"),
@@ -1052,6 +1063,7 @@ var propMeta = z14.union([
1052
1063
  resource2,
1053
1064
  code,
1054
1065
  codeText,
1066
+ jsonCode,
1055
1067
  color,
1056
1068
  boolean,
1057
1069
  radio,
@@ -1813,6 +1825,289 @@ var summary = [
1813
1825
  { property: "box-sizing", value: { type: "keyword", value: "border-box" } }
1814
1826
  ];
1815
1827
 
1828
+ // src/json-ld-utils.ts
1829
+ var isJsonObject = (value) => typeof value === "object" && value !== null && Array.isArray(value) === false;
1830
+ var appendJsonPath = (path, key) => typeof key === "number" ? `${path}[${key}]` : /^[A-Za-z_$][\w$]*$/.test(key) ? `${path}.${key}` : `${path}[${JSON.stringify(key)}]`;
1831
+ var getJsonLdTypes = (value) => typeof value === "string" ? [value] : Array.isArray(value) && value.every((item) => typeof item === "string") ? value : [];
1832
+
1833
+ // src/json-ld.ts
1834
+ var pushKeywordTypeError = (diagnostics, path, message) => {
1835
+ diagnostics.push({
1836
+ severity: "error",
1837
+ code: "invalid-keyword-value",
1838
+ path,
1839
+ message
1840
+ });
1841
+ };
1842
+ var escapeJsonLdScriptText = (value) => value.replace(/</g, "\\u003c");
1843
+ var validateContextTermDefinition = (definition, path, diagnostics) => {
1844
+ if (definition === null || typeof definition === "string" || isJsonObject(definition)) {
1845
+ if (isJsonObject(definition) && definition["@context"] !== void 0) {
1846
+ validateContext(
1847
+ definition["@context"],
1848
+ appendJsonPath(path, "@context"),
1849
+ diagnostics
1850
+ );
1851
+ }
1852
+ return;
1853
+ }
1854
+ diagnostics.push({
1855
+ severity: "error",
1856
+ code: "invalid-context",
1857
+ path,
1858
+ message: "JSON-LD context terms must map to a string, object, or null."
1859
+ });
1860
+ };
1861
+ var validateContext = (context, path, diagnostics) => {
1862
+ if (context === null || typeof context === "string") {
1863
+ return;
1864
+ }
1865
+ if (Array.isArray(context)) {
1866
+ context.forEach(
1867
+ (item, index) => validateContext(item, appendJsonPath(path, index), diagnostics)
1868
+ );
1869
+ return;
1870
+ }
1871
+ if (isJsonObject(context) === false) {
1872
+ diagnostics.push({
1873
+ severity: "error",
1874
+ code: "invalid-context",
1875
+ path,
1876
+ message: "@context must be a string, object, array of contexts, or null."
1877
+ });
1878
+ return;
1879
+ }
1880
+ for (const keyword of ["@base", "@vocab", "@language"]) {
1881
+ if (context[keyword] !== void 0 && context[keyword] !== null && typeof context[keyword] !== "string") {
1882
+ diagnostics.push({
1883
+ severity: "error",
1884
+ code: "invalid-context",
1885
+ path: appendJsonPath(path, keyword),
1886
+ message: `${keyword} must be a string or null.`
1887
+ });
1888
+ }
1889
+ }
1890
+ if (context["@direction"] !== void 0 && context["@direction"] !== null && context["@direction"] !== "ltr" && context["@direction"] !== "rtl") {
1891
+ diagnostics.push({
1892
+ severity: "error",
1893
+ code: "invalid-context",
1894
+ path: appendJsonPath(path, "@direction"),
1895
+ message: '@direction must be "ltr", "rtl", or null.'
1896
+ });
1897
+ }
1898
+ if (context["@propagate"] !== void 0 && typeof context["@propagate"] !== "boolean") {
1899
+ diagnostics.push({
1900
+ severity: "error",
1901
+ code: "invalid-context",
1902
+ path: appendJsonPath(path, "@propagate"),
1903
+ message: "@propagate must be a boolean."
1904
+ });
1905
+ }
1906
+ if (context["@version"] !== void 0 && context["@version"] !== 1.1) {
1907
+ diagnostics.push({
1908
+ severity: "error",
1909
+ code: "invalid-context",
1910
+ path: appendJsonPath(path, "@version"),
1911
+ message: "@version must be 1.1."
1912
+ });
1913
+ }
1914
+ for (const [term, definition] of Object.entries(context)) {
1915
+ if (term.startsWith("@")) {
1916
+ continue;
1917
+ }
1918
+ validateContextTermDefinition(
1919
+ definition,
1920
+ appendJsonPath(path, term),
1921
+ diagnostics
1922
+ );
1923
+ }
1924
+ };
1925
+ var validateNestedValues = (value, path, diagnostics) => {
1926
+ if (isJsonObject(value)) {
1927
+ validateNode(value, path, diagnostics);
1928
+ return;
1929
+ }
1930
+ if (Array.isArray(value)) {
1931
+ value.forEach((item, index) => {
1932
+ if (isJsonObject(item) || Array.isArray(item)) {
1933
+ validateNestedValues(item, appendJsonPath(path, index), diagnostics);
1934
+ }
1935
+ });
1936
+ }
1937
+ };
1938
+ var validateNode = (value, path, diagnostics) => {
1939
+ if (Array.isArray(value)) {
1940
+ value.forEach(
1941
+ (item, index) => validateNode(item, appendJsonPath(path, index), diagnostics)
1942
+ );
1943
+ return;
1944
+ }
1945
+ if (isJsonObject(value) === false) {
1946
+ diagnostics.push({
1947
+ severity: "error",
1948
+ code: "invalid-root",
1949
+ path,
1950
+ message: "JSON-LD nodes must be objects."
1951
+ });
1952
+ return;
1953
+ }
1954
+ if (value["@context"] !== void 0) {
1955
+ validateContext(
1956
+ value["@context"],
1957
+ appendJsonPath(path, "@context"),
1958
+ diagnostics
1959
+ );
1960
+ }
1961
+ const typeValue = value["@type"];
1962
+ if (typeValue !== void 0 && (getJsonLdTypes(typeValue).length === 0 || Array.isArray(typeValue) && typeValue.length === 0)) {
1963
+ pushKeywordTypeError(
1964
+ diagnostics,
1965
+ appendJsonPath(path, "@type"),
1966
+ "@type must be a non-empty string or array of strings."
1967
+ );
1968
+ }
1969
+ if (value["@id"] !== void 0 && typeof value["@id"] !== "string") {
1970
+ pushKeywordTypeError(
1971
+ diagnostics,
1972
+ appendJsonPath(path, "@id"),
1973
+ "@id must be a string."
1974
+ );
1975
+ }
1976
+ if (value["@graph"] !== void 0 && isJsonObject(value["@graph"]) === false && Array.isArray(value["@graph"]) === false) {
1977
+ pushKeywordTypeError(
1978
+ diagnostics,
1979
+ appendJsonPath(path, "@graph"),
1980
+ "@graph must be an object or array of objects."
1981
+ );
1982
+ }
1983
+ if (value["@language"] !== void 0 && value["@language"] !== null && typeof value["@language"] !== "string") {
1984
+ pushKeywordTypeError(
1985
+ diagnostics,
1986
+ appendJsonPath(path, "@language"),
1987
+ "@language must be a string or null."
1988
+ );
1989
+ }
1990
+ if (value["@nest"] !== void 0 && isJsonObject(value["@nest"]) === false && (Array.isArray(value["@nest"]) === false || value["@nest"].every(isJsonObject) === false)) {
1991
+ pushKeywordTypeError(
1992
+ diagnostics,
1993
+ appendJsonPath(path, "@nest"),
1994
+ "@nest must be an object or array of objects."
1995
+ );
1996
+ }
1997
+ if (value["@reverse"] !== void 0 && isJsonObject(value["@reverse"]) === false) {
1998
+ pushKeywordTypeError(
1999
+ diagnostics,
2000
+ appendJsonPath(path, "@reverse"),
2001
+ "@reverse must be an object."
2002
+ );
2003
+ }
2004
+ for (const keyword of ["@index"]) {
2005
+ if (value[keyword] !== void 0 && typeof value[keyword] !== "string") {
2006
+ pushKeywordTypeError(
2007
+ diagnostics,
2008
+ appendJsonPath(path, keyword),
2009
+ `${keyword} must be a string.`
2010
+ );
2011
+ }
2012
+ }
2013
+ if (value["@direction"] !== void 0 && value["@direction"] !== "ltr" && value["@direction"] !== "rtl" && value["@direction"] !== null) {
2014
+ pushKeywordTypeError(
2015
+ diagnostics,
2016
+ appendJsonPath(path, "@direction"),
2017
+ '@direction must be "ltr", "rtl", or null.'
2018
+ );
2019
+ }
2020
+ if ("@value" in value) {
2021
+ const invalidKeys = ["@id", "@graph", "@list", "@set", "@reverse"].filter(
2022
+ (key) => key in value
2023
+ );
2024
+ const isJsonLiteral = value["@type"] === "@json";
2025
+ const hasStructuredValue = typeof value["@value"] === "object" && value["@value"] !== null;
2026
+ if (invalidKeys.length > 0 || hasStructuredValue && isJsonLiteral === false || "@type" in value && value["@type"] !== "@json" && ("@language" in value || "@direction" in value)) {
2027
+ diagnostics.push({
2028
+ severity: "error",
2029
+ code: "invalid-value-object",
2030
+ path,
2031
+ message: "A JSON-LD value object has an incompatible keyword or @value shape."
2032
+ });
2033
+ }
2034
+ }
2035
+ for (const [property, propertyValue] of Object.entries(value)) {
2036
+ const propertyPath = appendJsonPath(path, property);
2037
+ if (property === "@context") {
2038
+ continue;
2039
+ }
2040
+ if (["@graph", "@included", "@nest", "@reverse"].includes(property)) {
2041
+ validateNode(propertyValue, propertyPath, diagnostics);
2042
+ continue;
2043
+ }
2044
+ if (property.startsWith("@")) {
2045
+ if (["@list", "@set"].includes(property)) {
2046
+ validateNestedValues(propertyValue, propertyPath, diagnostics);
2047
+ }
2048
+ continue;
2049
+ }
2050
+ validateNestedValues(propertyValue, propertyPath, diagnostics);
2051
+ }
2052
+ };
2053
+ var isJsonLdData = (value, ancestors) => {
2054
+ if (value === null || typeof value === "string" || typeof value === "boolean" || typeof value === "number" && Number.isFinite(value)) {
2055
+ return true;
2056
+ }
2057
+ if (typeof value !== "object" || value === null || ancestors.has(value)) {
2058
+ return false;
2059
+ }
2060
+ const prototype = Object.getPrototypeOf(value);
2061
+ if (Array.isArray(value) === false && prototype !== Object.prototype) {
2062
+ return false;
2063
+ }
2064
+ ancestors.add(value);
2065
+ const isValid = Array.isArray(value) ? value.every((item) => isJsonLdData(item, ancestors)) : Object.values(value).every((item) => isJsonLdData(item, ancestors));
2066
+ ancestors.delete(value);
2067
+ return isValid;
2068
+ };
2069
+ var isJsonLdValue = (value) => (Array.isArray(value) || isJsonObject(value)) && isJsonLdData(value, /* @__PURE__ */ new Set());
2070
+ var parseJsonLd = (input2) => {
2071
+ try {
2072
+ const value = typeof input2 === "string" ? JSON.parse(input2) : input2;
2073
+ if (isJsonLdValue(value)) {
2074
+ return { success: true, value };
2075
+ }
2076
+ } catch {
2077
+ }
2078
+ return { success: false };
2079
+ };
2080
+ var validateJsonLd = (input2) => {
2081
+ const parsed = parseJsonLd(input2);
2082
+ if (parsed.success === false) {
2083
+ return {
2084
+ success: false,
2085
+ diagnostics: [
2086
+ {
2087
+ severity: "error",
2088
+ code: typeof input2 === "string" ? "invalid-json" : "invalid-root",
2089
+ path: "$",
2090
+ message: "JSON-LD must be a valid JSON object or array."
2091
+ }
2092
+ ]
2093
+ };
2094
+ }
2095
+ const diagnostics = [];
2096
+ validateNode(parsed.value, "$", diagnostics);
2097
+ if (diagnostics.length > 0) {
2098
+ return { success: false, value: parsed.value, diagnostics };
2099
+ }
2100
+ return { success: true, value: parsed.value, diagnostics };
2101
+ };
2102
+ var hasTopLevelJsonLdContext = (value) => {
2103
+ if (Array.isArray(value)) {
2104
+ return value.some(
2105
+ (item) => typeof item === "object" && item !== null && "@context" in item
2106
+ );
2107
+ }
2108
+ return "@context" in value;
2109
+ };
2110
+
1816
2111
  // src/runtime.ts
1817
2112
  var tagProperty = "data-ws-tag";
1818
2113
 
@@ -2924,8 +3219,10 @@ var generateResources = ({
2924
3219
  resources: resources2
2925
3220
  }) => {
2926
3221
  const usedDataSources = /* @__PURE__ */ new Map();
3222
+ const generatedResourceIds = /* @__PURE__ */ new Set();
2927
3223
  let generatedRequests = "";
2928
3224
  for (const resource3 of resources2.values()) {
3225
+ generatedResourceIds.add(resource3.id);
2929
3226
  let generatedRequest = "";
2930
3227
  const resourceName = scope.getName(resource3.id, resource3.name);
2931
3228
  generatedRequest += ` const ${resourceName}: ResourceRequest = {
@@ -3014,7 +3311,7 @@ var generateResources = ({
3014
3311
  generated += ` const _data = new Map<string, ResourceRequest>([
3015
3312
  `;
3016
3313
  for (const dataSource2 of dataSources2.values()) {
3017
- if (dataSource2.type === "resource") {
3314
+ if (dataSource2.type === "resource" && generatedResourceIds.has(dataSource2.resourceId)) {
3018
3315
  const name = scope.getName(dataSource2.resourceId, dataSource2.name);
3019
3316
  generated += ` ["${name}", ${name}],
3020
3317
  `;
@@ -3025,7 +3322,7 @@ var generateResources = ({
3025
3322
  generated += ` const _action = new Map<string, ResourceRequest>([
3026
3323
  `;
3027
3324
  for (const prop2 of props2.values()) {
3028
- if (prop2.type === "resource") {
3325
+ if (prop2.type === "resource" && generatedResourceIds.has(prop2.value)) {
3029
3326
  const name = scope.getName(prop2.value, prop2.name);
3030
3327
  generated += ` ["${name}", ${name}],
3031
3328
  `;
@@ -3675,6 +3972,7 @@ export {
3675
3972
  elementComponent,
3676
3973
  encodeDataVariableId as encodeDataSourceVariable,
3677
3974
  encodeDataVariableId,
3975
+ escapeJsonLdScriptText,
3678
3976
  executeExpression,
3679
3977
  expressionChild,
3680
3978
  fileAsset,
@@ -3711,6 +4009,7 @@ export {
3711
4009
  getPagePath,
3712
4010
  getStaticSiteMapXml,
3713
4011
  getStyleDeclKey,
4012
+ hasTopLevelJsonLdContext,
3714
4013
  homePagePath,
3715
4014
  idChild,
3716
4015
  imageAsset,
@@ -3751,6 +4050,7 @@ export {
3751
4050
  pageTitle,
3752
4051
  pages,
3753
4052
  parseComponentName,
4053
+ parseJsonLd,
3754
4054
  parseObjectExpression,
3755
4055
  portalComponent,
3756
4056
  presetStyleDecl,
@@ -3784,6 +4084,7 @@ export {
3784
4084
  toRuntimeAsset,
3785
4085
  transpileExpression,
3786
4086
  validateFileName,
4087
+ validateJsonLd,
3787
4088
  viewAnimation,
3788
4089
  webstudioFragment,
3789
4090
  wsComponentMeta