1- import {
2- categoriesByTag ,
3- childrenCategoriesByTag ,
4- } from "@webstudio-is/html-data" ;
1+ import { elementsByTag } from "@webstudio-is/html-data" ;
52import {
63 parseComponentName ,
74 type ContentModel ,
@@ -55,7 +52,7 @@ const isIntersected = (arrayA: string[], arrayB: string[]) => {
5552 * so img can be put into links and buttons
5653 */
5754const isTagInteractive = ( tag : string ) => {
58- return tag !== "img" && categoriesByTag [ tag ] . includes ( "interactive" ) ;
55+ return tag !== "img" && elementsByTag [ tag ] . categories . includes ( "interactive" ) ;
5956} ;
6057
6158const isTagSatisfyingContentModel = ( {
@@ -87,7 +84,7 @@ const isTagSatisfyingContentModel = ({
8784 // valid way to nest interactive elements
8885 if (
8986 allowedCategories . includes ( "labelable" ) &&
90- categoriesByTag [ tag ] . includes ( "labelable" )
87+ elementsByTag [ tag ] . categories . includes ( "labelable" )
9188 ) {
9289 return true ;
9390 }
@@ -102,47 +99,47 @@ const isTagSatisfyingContentModel = ({
10299 return false ;
103100 }
104101 // instance matches parent constraints
105- return isIntersected ( allowedCategories , categoriesByTag [ tag ] ) ;
102+ return isIntersected ( allowedCategories , elementsByTag [ tag ] . categories ) ;
106103} ;
107104
108105/**
109106 * compute possible categories for tag children
110107 */
111- const getTagChildrenCategories = (
108+ const getElementChildren = (
112109 tag : undefined | string ,
113110 allowedCategories : undefined | string [ ]
114111) => {
115112 // components without tag behave like transparent category
116113 // and pass through parent constraints
117- let childrenCategories : string [ ] =
118- tag === undefined ? [ "transparent" ] : childrenCategoriesByTag [ tag ] ;
119- if ( childrenCategories . includes ( "transparent" ) && allowedCategories ) {
120- childrenCategories = allowedCategories ;
114+ let elementChildren : string [ ] =
115+ tag === undefined ? [ "transparent" ] : elementsByTag [ tag ] . children ;
116+ if ( elementChildren . includes ( "transparent" ) && allowedCategories ) {
117+ elementChildren = allowedCategories ;
121118 }
122119 // introduce custom non-interactive category to restrict nesting interactive elements
123120 // like button > button or a > input
124121 if (
125122 tag &&
126123 ( isTagInteractive ( tag ) || allowedCategories ?. includes ( "non-interactive" ) )
127124 ) {
128- childrenCategories = [ ...childrenCategories , "non-interactive" ] ;
125+ elementChildren = [ ...elementChildren , "non-interactive" ] ;
129126 }
130127 // interactive exception, label > input or label > button are considered
131128 // valid way to nest interactive elements
132129 // pass through labelable to match controls with labelable category
133130 if ( tag === "label" || allowedCategories ?. includes ( "labelable" ) ) {
134131 // stop passing through labelable to control children
135132 // to prevent label > button > input
136- if ( tag && categoriesByTag [ tag ] . includes ( "labelable" ) === false ) {
137- childrenCategories = [ ...childrenCategories , "labelable" ] ;
133+ if ( tag && elementsByTag [ tag ] . categories . includes ( "labelable" ) === false ) {
134+ elementChildren = [ ...elementChildren , "labelable" ] ;
138135 }
139136 }
140137 // introduce custom non-form category to restrict nesting form elements
141138 // like form > div > form
142139 if ( tag === "form" || allowedCategories ?. includes ( "non-form" ) ) {
143- childrenCategories = [ ...childrenCategories , "non-form" ] ;
140+ elementChildren = [ ...elementChildren , "non-form" ] ;
144141 }
145- return childrenCategories ;
142+ return elementChildren ;
146143} ;
147144
148145/**
@@ -171,7 +168,7 @@ const computeAllowedCategories = ({
171168 continue ;
172169 }
173170 const tag = getTag ( { instance, metas, props } ) ;
174- allowedCategories = getTagChildrenCategories ( tag , allowedCategories ) ;
171+ allowedCategories = getElementChildren ( tag , allowedCategories ) ;
175172 }
176173 return allowedCategories ;
177174} ;
@@ -375,7 +372,7 @@ export const isTreeSatisfyingContentModel = ({
375372 }
376373 let isSatisfying = isTagSatisfying && isComponentSatisfying ;
377374 const contentModel = getComponentContentModel ( metas . get ( instance . component ) ) ;
378- allowedCategories = getTagChildrenCategories ( tag , allowedCategories ) ;
375+ allowedCategories = getElementChildren ( tag , allowedCategories ) ;
379376 allowedParentCategories = contentModel . children ;
380377 if ( contentModel . descendants ) {
381378 allowedAncestorCategories ??= [ ] ;
@@ -584,11 +581,11 @@ export const findClosestContainer = ({
584581 }
585582 const tag = getTag ( { instance, props, metas } ) ;
586583 const meta = metas . get ( instance . component ) ;
587- const childrenCategories = tag ? childrenCategoriesByTag [ tag ] : undefined ;
588- const childrenComponentCategories = getComponentContentModel ( meta ) . children ;
584+ const elementChildren = tag ? elementsByTag [ tag ] . children : undefined ;
585+ const componentChildren = getComponentContentModel ( meta ) . children ;
589586 if (
590- childrenComponentCategories . length === 0 ||
591- ( childrenCategories && childrenCategories . length === 0 )
587+ componentChildren . length === 0 ||
588+ ( elementChildren && elementChildren . length === 0 )
592589 ) {
593590 continue ;
594591 }
@@ -621,11 +618,11 @@ export const findClosestNonTextualContainer = ({
621618 }
622619 const tag = getTag ( { instance, props, metas } ) ;
623620 const meta = metas . get ( instance . component ) ;
624- const childrenCategories = tag ? childrenCategoriesByTag [ tag ] : undefined ;
625- const childrenComponentCategories = getComponentContentModel ( meta ) . children ;
621+ const elementChildren = tag ? elementsByTag [ tag ] . children : undefined ;
622+ const componentChildren = getComponentContentModel ( meta ) . children ;
626623 if (
627- childrenComponentCategories . length === 0 ||
628- ( childrenCategories && childrenCategories . length === 0 )
624+ componentChildren . length === 0 ||
625+ ( elementChildren && elementChildren . length === 0 )
629626 ) {
630627 continue ;
631628 }
0 commit comments