@webstudio-is/sdk 0.265.0 → 0.266.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 +0 -113
- package/lib/types/index.d.ts +0 -1
- package/package.json +7 -12
- package/lib/migrations/webstudio-data.js +0 -163
- package/lib/types/migrations/index.d.ts +0 -1
- package/lib/types/migrations/pages.d.ts +0 -7
- package/lib/types/migrations/styles.d.ts +0 -2
- package/lib/types/migrations/webstudio-data.d.ts +0 -8
package/lib/index.js
CHANGED
|
@@ -2549,117 +2549,6 @@ var getStaticSiteMapXml = (pages, updatedAt) => {
|
|
|
2549
2549
|
}));
|
|
2550
2550
|
};
|
|
2551
2551
|
|
|
2552
|
-
// src/migrations/pages.ts
|
|
2553
|
-
var toMap = (items, normalizeItem = (item) => item) => {
|
|
2554
|
-
if (items instanceof Map) {
|
|
2555
|
-
return new Map(
|
|
2556
|
-
Array.from(items, ([id, item]) => [id, normalizeItem(item)])
|
|
2557
|
-
);
|
|
2558
|
-
}
|
|
2559
|
-
const list = Array.isArray(items) ? items : Object.values(items);
|
|
2560
|
-
return new Map(list.map((item) => [item.id, normalizeItem(item)]));
|
|
2561
|
-
};
|
|
2562
|
-
var normalizePage = (page) => ({
|
|
2563
|
-
...page,
|
|
2564
|
-
meta: page.meta ?? {}
|
|
2565
|
-
});
|
|
2566
|
-
var isLegacyPages = (pages) => {
|
|
2567
|
-
if (typeof pages !== "object" || pages === null) {
|
|
2568
|
-
return false;
|
|
2569
|
-
}
|
|
2570
|
-
return "homePage" in pages && Array.isArray(pages.pages);
|
|
2571
|
-
};
|
|
2572
|
-
var isSerializedPages = (pages) => {
|
|
2573
|
-
if (typeof pages !== "object" || pages === null) {
|
|
2574
|
-
return false;
|
|
2575
|
-
}
|
|
2576
|
-
const candidate = pages;
|
|
2577
|
-
return typeof candidate.homePageId === "string" && typeof candidate.rootFolderId === "string" && candidate.pages !== void 0 && candidate.folders !== void 0;
|
|
2578
|
-
};
|
|
2579
|
-
var serializePages = (pages) => {
|
|
2580
|
-
const parsedPages = Pages.parse(pages);
|
|
2581
|
-
return {
|
|
2582
|
-
meta: parsedPages.meta,
|
|
2583
|
-
compiler: parsedPages.compiler,
|
|
2584
|
-
redirects: parsedPages.redirects,
|
|
2585
|
-
homePageId: parsedPages.homePageId,
|
|
2586
|
-
rootFolderId: parsedPages.rootFolderId,
|
|
2587
|
-
pages: Array.from(parsedPages.pages.values()),
|
|
2588
|
-
folders: Array.from(parsedPages.folders.values())
|
|
2589
|
-
};
|
|
2590
|
-
};
|
|
2591
|
-
var migratePages = (pages) => {
|
|
2592
|
-
if (isSerializedPages(pages) && pages.pages instanceof Map && pages.folders instanceof Map) {
|
|
2593
|
-
return pages;
|
|
2594
|
-
}
|
|
2595
|
-
if (isSerializedPages(pages)) {
|
|
2596
|
-
return {
|
|
2597
|
-
meta: pages.meta,
|
|
2598
|
-
compiler: pages.compiler,
|
|
2599
|
-
redirects: pages.redirects,
|
|
2600
|
-
homePageId: pages.homePageId,
|
|
2601
|
-
rootFolderId: pages.rootFolderId,
|
|
2602
|
-
pages: toMap(pages.pages, normalizePage),
|
|
2603
|
-
folders: toMap(pages.folders)
|
|
2604
|
-
};
|
|
2605
|
-
}
|
|
2606
|
-
if (isLegacyPages(pages) === false) {
|
|
2607
|
-
throw new Error("Pages data has unsupported shape.");
|
|
2608
|
-
}
|
|
2609
|
-
const homePage = {
|
|
2610
|
-
...normalizePage(pages.homePage),
|
|
2611
|
-
path: ""
|
|
2612
|
-
};
|
|
2613
|
-
const nextPages = /* @__PURE__ */ new Map([[homePage.id, homePage]]);
|
|
2614
|
-
for (const page of pages.pages) {
|
|
2615
|
-
if (page.id === homePage.id) {
|
|
2616
|
-
continue;
|
|
2617
|
-
}
|
|
2618
|
-
nextPages.set(page.id, normalizePage(page));
|
|
2619
|
-
}
|
|
2620
|
-
const nextFolders = /* @__PURE__ */ new Map();
|
|
2621
|
-
for (const folder of pages.folders ?? []) {
|
|
2622
|
-
nextFolders.set(folder.id, { ...folder, children: [...folder.children] });
|
|
2623
|
-
}
|
|
2624
|
-
const rootFolder = Array.from(nextFolders.values()).find(isRootFolder) ?? pages.folders?.[0] ?? {
|
|
2625
|
-
id: ROOT_FOLDER_ID,
|
|
2626
|
-
name: "Root",
|
|
2627
|
-
slug: "",
|
|
2628
|
-
children: []
|
|
2629
|
-
};
|
|
2630
|
-
if (nextFolders.has(rootFolder.id) === false) {
|
|
2631
|
-
nextFolders.set(rootFolder.id, { ...rootFolder, children: [] });
|
|
2632
|
-
}
|
|
2633
|
-
const nextRootFolder = nextFolders.get(rootFolder.id);
|
|
2634
|
-
if (nextRootFolder === void 0) {
|
|
2635
|
-
throw new Error("Pages must include a root folder.");
|
|
2636
|
-
}
|
|
2637
|
-
for (const folder of nextFolders.values()) {
|
|
2638
|
-
folder.children = folder.children.filter(
|
|
2639
|
-
(childId) => childId !== homePage.id
|
|
2640
|
-
);
|
|
2641
|
-
}
|
|
2642
|
-
nextRootFolder.children.unshift(homePage.id);
|
|
2643
|
-
const referencedIds = new Set(
|
|
2644
|
-
Array.from(nextFolders.values()).flatMap((folder) => folder.children)
|
|
2645
|
-
);
|
|
2646
|
-
for (const page of pages.pages) {
|
|
2647
|
-
if (page.id !== homePage.id && referencedIds.has(page.id) === false) {
|
|
2648
|
-
nextRootFolder.children.push(page.id);
|
|
2649
|
-
referencedIds.add(page.id);
|
|
2650
|
-
}
|
|
2651
|
-
}
|
|
2652
|
-
return {
|
|
2653
|
-
meta: pages.meta,
|
|
2654
|
-
compiler: pages.compiler,
|
|
2655
|
-
redirects: pages.redirects,
|
|
2656
|
-
homePageId: homePage.id,
|
|
2657
|
-
rootFolderId: rootFolder.id,
|
|
2658
|
-
pages: nextPages,
|
|
2659
|
-
folders: nextFolders
|
|
2660
|
-
};
|
|
2661
|
-
};
|
|
2662
|
-
|
|
2663
2552
|
// src/scope.ts
|
|
2664
2553
|
import reservedIdentifiers from "reserved-identifiers";
|
|
2665
2554
|
var identifiers = reservedIdentifiers({ includeGlobalProperties: true });
|
|
@@ -3357,7 +3246,6 @@ export {
|
|
|
3357
3246
|
isRootFolder,
|
|
3358
3247
|
lintExpression,
|
|
3359
3248
|
matchPathnameParams,
|
|
3360
|
-
migratePages,
|
|
3361
3249
|
parseComponentName,
|
|
3362
3250
|
parseObjectExpression,
|
|
3363
3251
|
portalComponent,
|
|
@@ -3365,7 +3253,6 @@ export {
|
|
|
3365
3253
|
replaceFormActionsWithResources,
|
|
3366
3254
|
rootComponent,
|
|
3367
3255
|
scrollAnimationSchema,
|
|
3368
|
-
serializePages,
|
|
3369
3256
|
systemParameter,
|
|
3370
3257
|
tags,
|
|
3371
3258
|
toRuntimeAsset,
|
package/lib/types/index.d.ts
CHANGED
|
@@ -16,7 +16,6 @@ export * from "./assets";
|
|
|
16
16
|
export * from "./core-metas";
|
|
17
17
|
export * from "./instances-utils";
|
|
18
18
|
export * from "./page-utils";
|
|
19
|
-
export * from "./migrations";
|
|
20
19
|
export * from "./scope";
|
|
21
20
|
export * from "./expression";
|
|
22
21
|
export * from "./resources-generator";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webstudio-is/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.266.0",
|
|
4
4
|
"description": "Webstudio project data schema",
|
|
5
5
|
"author": "Webstudio <github@webstudio.is>",
|
|
6
6
|
"homepage": "https://webstudio.is",
|
|
@@ -28,11 +28,6 @@
|
|
|
28
28
|
"types": "./lib/types/core-templates.d.ts",
|
|
29
29
|
"import": "./lib/core-templates.js"
|
|
30
30
|
},
|
|
31
|
-
"./migrations/webstudio-data": {
|
|
32
|
-
"webstudio": "./src/migrations/webstudio-data.ts",
|
|
33
|
-
"types": "./lib/types/migrations/webstudio-data.d.ts",
|
|
34
|
-
"import": "./lib/migrations/webstudio-data.js"
|
|
35
|
-
},
|
|
36
31
|
"./router-path-test-data": {
|
|
37
32
|
"webstudio": "./src/router-path-test-data.ts"
|
|
38
33
|
}
|
|
@@ -51,22 +46,22 @@
|
|
|
51
46
|
"type-fest": "^4.37.0",
|
|
52
47
|
"warn-once": "^0.1.1",
|
|
53
48
|
"zod": "^3.24.2",
|
|
54
|
-
"@webstudio-is/
|
|
55
|
-
"@webstudio-is/icons": "0.
|
|
56
|
-
"@webstudio-is/css-engine": "0.
|
|
57
|
-
"@webstudio-is/fonts": "0.265.0"
|
|
49
|
+
"@webstudio-is/fonts": "0.266.0",
|
|
50
|
+
"@webstudio-is/icons": "0.266.0",
|
|
51
|
+
"@webstudio-is/css-engine": "0.266.0"
|
|
58
52
|
},
|
|
59
53
|
"devDependencies": {
|
|
60
54
|
"html-tags": "^4.0.0",
|
|
61
55
|
"vitest": "^3.1.2",
|
|
62
|
-
"@webstudio-is/template": "0.
|
|
56
|
+
"@webstudio-is/template": "0.266.0",
|
|
57
|
+
"@webstudio-is/css-data": "0.266.0",
|
|
63
58
|
"@webstudio-is/tsconfig": "1.0.7"
|
|
64
59
|
},
|
|
65
60
|
"scripts": {
|
|
66
61
|
"typecheck": "tsgo --noEmit -p tsconfig.typecheck.json",
|
|
67
62
|
"test": "vitest run",
|
|
68
63
|
"build:normalize.css": "tsx --conditions=webstudio ./scripts/normalize.css.ts && prettier --write src/__generated__/normalize.css.ts",
|
|
69
|
-
"build": "rm -rf lib && esbuild src/index.ts src/runtime.ts src/__generated__/normalize.css.ts src/core-templates.tsx
|
|
64
|
+
"build": "rm -rf lib && esbuild src/index.ts src/runtime.ts src/__generated__/normalize.css.ts src/core-templates.tsx --outdir=lib --bundle --format=esm --packages=external",
|
|
70
65
|
"dts": "tsc --project tsconfig.dts.json"
|
|
71
66
|
}
|
|
72
67
|
}
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
// src/page-utils.ts
|
|
2
|
-
var ROOT_FOLDER_ID = "root";
|
|
3
|
-
var isRootFolder = ({ id }) => id === ROOT_FOLDER_ID;
|
|
4
|
-
|
|
5
|
-
// src/migrations/pages.ts
|
|
6
|
-
var toMap = (items, normalizeItem = (item) => item) => {
|
|
7
|
-
if (items instanceof Map) {
|
|
8
|
-
return new Map(
|
|
9
|
-
Array.from(items, ([id, item]) => [id, normalizeItem(item)])
|
|
10
|
-
);
|
|
11
|
-
}
|
|
12
|
-
const list = Array.isArray(items) ? items : Object.values(items);
|
|
13
|
-
return new Map(list.map((item) => [item.id, normalizeItem(item)]));
|
|
14
|
-
};
|
|
15
|
-
var normalizePage = (page) => ({
|
|
16
|
-
...page,
|
|
17
|
-
meta: page.meta ?? {}
|
|
18
|
-
});
|
|
19
|
-
var isLegacyPages = (pages) => {
|
|
20
|
-
if (typeof pages !== "object" || pages === null) {
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
return "homePage" in pages && Array.isArray(pages.pages);
|
|
24
|
-
};
|
|
25
|
-
var isSerializedPages = (pages) => {
|
|
26
|
-
if (typeof pages !== "object" || pages === null) {
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
const candidate = pages;
|
|
30
|
-
return typeof candidate.homePageId === "string" && typeof candidate.rootFolderId === "string" && candidate.pages !== void 0 && candidate.folders !== void 0;
|
|
31
|
-
};
|
|
32
|
-
var migratePages = (pages) => {
|
|
33
|
-
if (isSerializedPages(pages) && pages.pages instanceof Map && pages.folders instanceof Map) {
|
|
34
|
-
return pages;
|
|
35
|
-
}
|
|
36
|
-
if (isSerializedPages(pages)) {
|
|
37
|
-
return {
|
|
38
|
-
meta: pages.meta,
|
|
39
|
-
compiler: pages.compiler,
|
|
40
|
-
redirects: pages.redirects,
|
|
41
|
-
homePageId: pages.homePageId,
|
|
42
|
-
rootFolderId: pages.rootFolderId,
|
|
43
|
-
pages: toMap(pages.pages, normalizePage),
|
|
44
|
-
folders: toMap(pages.folders)
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
if (isLegacyPages(pages) === false) {
|
|
48
|
-
throw new Error("Pages data has unsupported shape.");
|
|
49
|
-
}
|
|
50
|
-
const homePage = {
|
|
51
|
-
...normalizePage(pages.homePage),
|
|
52
|
-
path: ""
|
|
53
|
-
};
|
|
54
|
-
const nextPages = /* @__PURE__ */ new Map([[homePage.id, homePage]]);
|
|
55
|
-
for (const page of pages.pages) {
|
|
56
|
-
if (page.id === homePage.id) {
|
|
57
|
-
continue;
|
|
58
|
-
}
|
|
59
|
-
nextPages.set(page.id, normalizePage(page));
|
|
60
|
-
}
|
|
61
|
-
const nextFolders = /* @__PURE__ */ new Map();
|
|
62
|
-
for (const folder of pages.folders ?? []) {
|
|
63
|
-
nextFolders.set(folder.id, { ...folder, children: [...folder.children] });
|
|
64
|
-
}
|
|
65
|
-
const rootFolder = Array.from(nextFolders.values()).find(isRootFolder) ?? pages.folders?.[0] ?? {
|
|
66
|
-
id: ROOT_FOLDER_ID,
|
|
67
|
-
name: "Root",
|
|
68
|
-
slug: "",
|
|
69
|
-
children: []
|
|
70
|
-
};
|
|
71
|
-
if (nextFolders.has(rootFolder.id) === false) {
|
|
72
|
-
nextFolders.set(rootFolder.id, { ...rootFolder, children: [] });
|
|
73
|
-
}
|
|
74
|
-
const nextRootFolder = nextFolders.get(rootFolder.id);
|
|
75
|
-
if (nextRootFolder === void 0) {
|
|
76
|
-
throw new Error("Pages must include a root folder.");
|
|
77
|
-
}
|
|
78
|
-
for (const folder of nextFolders.values()) {
|
|
79
|
-
folder.children = folder.children.filter(
|
|
80
|
-
(childId) => childId !== homePage.id
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
nextRootFolder.children.unshift(homePage.id);
|
|
84
|
-
const referencedIds = new Set(
|
|
85
|
-
Array.from(nextFolders.values()).flatMap((folder) => folder.children)
|
|
86
|
-
);
|
|
87
|
-
for (const page of pages.pages) {
|
|
88
|
-
if (page.id !== homePage.id && referencedIds.has(page.id) === false) {
|
|
89
|
-
nextRootFolder.children.push(page.id);
|
|
90
|
-
referencedIds.add(page.id);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
return {
|
|
94
|
-
meta: pages.meta,
|
|
95
|
-
compiler: pages.compiler,
|
|
96
|
-
redirects: pages.redirects,
|
|
97
|
-
homePageId: homePage.id,
|
|
98
|
-
rootFolderId: rootFolder.id,
|
|
99
|
-
pages: nextPages,
|
|
100
|
-
folders: nextFolders
|
|
101
|
-
};
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
// src/migrations/styles.ts
|
|
105
|
-
import { hyphenateProperty, toValue } from "@webstudio-is/css-engine";
|
|
106
|
-
import {
|
|
107
|
-
camelCaseProperty,
|
|
108
|
-
expandShorthands,
|
|
109
|
-
parseCssValue
|
|
110
|
-
} from "@webstudio-is/css-data";
|
|
111
|
-
|
|
112
|
-
// src/schema/styles.ts
|
|
113
|
-
import { z } from "zod";
|
|
114
|
-
import { StyleValue } from "@webstudio-is/css-engine";
|
|
115
|
-
var StyleDeclRaw = z.object({
|
|
116
|
-
styleSourceId: z.string(),
|
|
117
|
-
breakpointId: z.string(),
|
|
118
|
-
state: z.optional(z.string()),
|
|
119
|
-
// @todo can't figure out how to make property to be enum
|
|
120
|
-
property: z.string(),
|
|
121
|
-
value: StyleValue,
|
|
122
|
-
listed: z.boolean().optional().describe("Whether the style is from the Advanced panel")
|
|
123
|
-
});
|
|
124
|
-
var StyleDecl = StyleDeclRaw;
|
|
125
|
-
var getStyleDeclKey = (styleDecl) => {
|
|
126
|
-
return `${styleDecl.styleSourceId}:${styleDecl.breakpointId}:${styleDecl.property}:${styleDecl.state ?? ""}`;
|
|
127
|
-
};
|
|
128
|
-
var Styles = z.map(z.string(), StyleDecl);
|
|
129
|
-
|
|
130
|
-
// src/migrations/styles.ts
|
|
131
|
-
var migratedShorthands = /* @__PURE__ */ new Set([
|
|
132
|
-
"overflow",
|
|
133
|
-
"transition",
|
|
134
|
-
"white-space",
|
|
135
|
-
"background-position"
|
|
136
|
-
]);
|
|
137
|
-
var migrateStylesMutable = (styles) => {
|
|
138
|
-
for (const [styleDeclKey, styleDecl] of styles) {
|
|
139
|
-
const property = hyphenateProperty(styleDecl.property);
|
|
140
|
-
if (migratedShorthands.has(property) === false) {
|
|
141
|
-
continue;
|
|
142
|
-
}
|
|
143
|
-
styles.delete(styleDeclKey);
|
|
144
|
-
const longhands = expandShorthands([[property, toValue(styleDecl.value)]]);
|
|
145
|
-
for (const [hyphenedProperty, value] of longhands) {
|
|
146
|
-
const longhandStyleDecl = {
|
|
147
|
-
...styleDecl,
|
|
148
|
-
property: camelCaseProperty(hyphenedProperty),
|
|
149
|
-
value: parseCssValue(hyphenedProperty, value)
|
|
150
|
-
};
|
|
151
|
-
styles.set(getStyleDeclKey(longhandStyleDecl), longhandStyleDecl);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
// src/migrations/webstudio-data.ts
|
|
157
|
-
var migrateWebstudioDataMutable = (data) => {
|
|
158
|
-
data.pages = migratePages(data.pages);
|
|
159
|
-
migrateStylesMutable(data.styles);
|
|
160
|
-
};
|
|
161
|
-
export {
|
|
162
|
-
migrateWebstudioDataMutable
|
|
163
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./pages";
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { type Folder, type Page, type Pages } from "../schema/pages";
|
|
2
|
-
export type SerializedPages = Omit<Pages, "pages" | "folders"> & {
|
|
3
|
-
pages: Page[];
|
|
4
|
-
folders: Folder[];
|
|
5
|
-
};
|
|
6
|
-
export declare const serializePages: (pages: Pages) => SerializedPages;
|
|
7
|
-
export declare const migratePages: (pages: unknown) => Pages;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { WebstudioData } from "../schema/webstudio";
|
|
2
|
-
/**
|
|
3
|
-
* Normalizes persisted project data after loading.
|
|
4
|
-
*
|
|
5
|
-
* This is intentionally idempotent because data can pass through multiple
|
|
6
|
-
* load boundaries before all callers stop seeing older persisted shapes.
|
|
7
|
-
*/
|
|
8
|
-
export declare const migrateWebstudioDataMutable: (data: WebstudioData) => void;
|