Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
experimental: support grid and grid-template shorthands (#3598)
Bogdan Chadkin8ca12a774270
diff --git a/packages/css-data/src/shorthands.test.ts b/packages/css-data/src/shorthands.test.tsindex cf653ec1fb..8c6eb79cd0 100644--- a/packages/css-data/src/shorthands.test.ts+++ b/packages/css-data/src/shorthands.test.ts@@ -871,10 +871,77 @@ test("expand scroll-margin/scroll-padding", () => {]);});+test("expand grid-template", () => {+ expect(expandShorthands([["grid-template", `none`]])).toEqual([+ ["grid-template-areas", "none"],+ ["grid-template-rows", "none"],+ ["grid-template-columns", "none"],+ ]);+ expect(expandShorthands([["grid-template", `100px 1fr / 50px 1fr`]])).toEqual(+ [+ ["grid-template-areas", "none"],+ ["grid-template-rows", "100px 1fr"],+ ["grid-template-columns", "50px 1fr"],+ ]+ );+ expect(+ expandShorthands([+ [+ "grid-template",+ `+ [header-top] "a a a" [header-bottom]+ [main-top] "b b b" 1fr [main-bottom]+ / auto 1fr auto+ `,+ ],+ ])+ ).toEqual([+ ["grid-template-areas", `"a a a""b b b"`],+ [+ "grid-template-rows",+ "[header-top][header-bottom][main-top]1fr[main-bottom]",+ ],+ ["grid-template-columns", "auto 1fr auto"],+ ]);+});++test("expand grid", () => {+ expect(expandShorthands([["grid", `none`]])).toEqual([+ ["grid-template-areas", "none"],+ ["grid-template-rows", "none"],+ ["grid-template-columns", "none"],+ ["grid-auto-flow.", "row"],+ ["grid-auto-rows", "auto"],+ ["grid-auto-columns", "auto"],+ ]);+ expect(expandShorthands([["grid", `100px 1fr / 50px 1fr`]])).toEqual([+ ["grid-template-areas", "none"],+ ["grid-template-rows", "100px 1fr"],+ ["grid-template-columns", "50px 1fr"],+ ["grid-auto-flow.", "row"],+ ["grid-auto-rows", "auto"],+ ["grid-auto-columns", "auto"],+ ]);+ expect(expandShorthands([["grid", `200px / auto-flow`]])).toEqual([+ ["grid-template-areas", "none"],+ ["grid-template-rows", "200px"],+ ["grid-template-columns", "none"],+ ["grid-auto-flow.", "column"],+ ["grid-auto-rows", "auto"],+ ["grid-auto-columns", "auto"],+ ]);+ expect(expandShorthands([["grid", `auto-flow dense / 30%`]])).toEqual([+ ["grid-template-areas", "none"],+ ["grid-template-rows", "none"],+ ["grid-template-columns", "30%"],+ ["grid-auto-flow.", "row dense"],+ ["grid-auto-rows", "auto"],+ ["grid-auto-columns", "auto"],+ ]);+});+test.todo("container");test.todo("contain-intrinsic-size");-test.todo("grid");-test.todo("grid-template");test.todo("white-space - not a shorthand in webflow");test.todo("text-wrap - not a shorthand in webflow");diff --git a/packages/css-data/src/shorthands.ts b/packages/css-data/src/shorthands.tsindex 9f6dd68513..11dae3f9f1 100644--- a/packages/css-data/src/shorthands.ts+++ b/packages/css-data/src/shorthands.ts@@ -745,6 +745,103 @@ const expandScrollTimeline = function* (value: CssNode) {] as const;};+/**+ *+ * grid-template =+ * none |+ * [ <'grid-template-rows'> / <'grid-template-columns'> ] |+ * [ <line-names>? <string> <track-size>? <line-names>? ]+ [ / <explicit-track-list> ]?+ *+ */+const expandGridTemplate = function* (value: CssNode) {+ let rows = createIdentifier("none");+ let columns = createIdentifier("none");+ let areas = createIdentifier("none");+ [rows = createIdentifier("none"), columns = createIdentifier("none")] =+ splitByOperator(value, "/");+ const rowsNodes: CssNode[] = [];+ const areasNodes: CssNode[] = [];+ for (const node of getValueList(rows)) {+ if (node.type === "String") {+ areasNodes.push(node);+ } else {+ rowsNodes.push(node);+ }+ }+ if (areasNodes.length > 0) {+ areas = createValueNode(areasNodes);+ rows = createValueNode(rowsNodes);+ }+ yield ["grid-template-areas", areas] as const;+ yield ["grid-template-rows", rows] as const;+ yield ["grid-template-columns", columns] as const;+};++/**+ *+ * grid =+ * <'grid-template'> |+ * <'grid-template-rows'> / [ auto-flow && dense? ] <'grid-auto-columns'>? |+ * [ auto-flow && dense? ] <'grid-auto-rows'>? / <'grid-template-columns'>+ *+ */+const expandGrid = function* (value: CssNode) {+ const areas = createIdentifier("none");+ let templateRows = createIdentifier("none");+ let templateColumns = createIdentifier("none");+ let autoFlow = createIdentifier("row");+ let autoRows = createIdentifier("auto");+ let autoColumns = createIdentifier("auto");+ const [rows = createIdentifier("none"), columns = createIdentifier("none")] =+ splitByOperator(value, "/");+ if (lexer.match(`<'grid-template'>`, value).matched) {+ yield* expandGridTemplate(value);+ yield ["grid-auto-flow.", autoFlow] as const;+ yield ["grid-auto-rows", autoRows] as const;+ yield ["grid-auto-columns", autoColumns] as const;+ return;+ }+ if (+ lexer.match(`[ auto-flow && dense? ] <'grid-auto-rows'>?`, rows).matched+ ) {+ const [autoFlowKeyword, denseKeyword, config] = parseUnordered(+ ["auto-flow", "dense", `<'grid-auto-rows'>?`],+ rows+ );+ if (autoFlowKeyword) {+ autoFlow = createIdentifier("row");+ if (denseKeyword) {+ autoFlow.children.appendList(denseKeyword.children);+ }+ }+ autoRows = config ?? createIdentifier("auto");+ templateColumns = columns;+ }+ if (+ lexer.match(`[ auto-flow && dense? ] <'grid-auto-columns'>?`, columns)+ .matched+ ) {+ const [autoFlowKeyword, denseKeyword, config] = parseUnordered(+ ["auto-flow", "dense", `<'grid-auto-columns'>?`],+ columns+ );+ if (autoFlowKeyword) {+ autoFlow = createIdentifier("column");+ if (denseKeyword) {+ autoFlow.children.appendList(denseKeyword.children);+ }+ }+ autoColumns = config ?? createIdentifier("auto");+ templateRows = rows;+ }+ yield ["grid-template-areas", areas] as const;+ yield ["grid-template-rows", templateRows] as const;+ yield ["grid-template-columns", templateColumns] as const;+ yield ["grid-auto-flow.", autoFlow] as const;+ yield ["grid-auto-rows", autoRows] as const;+ yield ["grid-auto-columns", autoColumns] as const;+};+const expandShorthand = function* (property: string, value: CssNode) {switch (property) {case "font":@@ -866,6 +963,14 @@ const expandShorthand = function* (property: string, value: CssNode) {break;}+ case "grid-template":+ yield* expandGridTemplate(value);+ break;++ case "grid":+ yield* expandGrid(value);+ break;+case "flex":yield* expandFlex(value);break;