@@ -31,11 +31,8 @@ import type {
3131import { encodeDataSourceVariable , getStyleDeclKey } from "@webstudio-is/sdk" ;
3232import type { StyleProperty , StyleValue } from "@webstudio-is/css-engine" ;
3333import {
34- computeInstancesConstraints ,
35- findClosestDroppableComponentIndex ,
3634 findClosestEditableInstanceSelector ,
3735 insertTemplateData ,
38- type InsertConstraints ,
3936 deleteInstanceMutable ,
4037 extractWebstudioFragment ,
4138 insertWebstudioFragmentCopy ,
@@ -189,11 +186,6 @@ const createFontAsset = (id: string, family: string): Asset => {
189186 } ;
190187} ;
191188
192- const emptyInsertConstraints : InsertConstraints = {
193- requiredAncestors : new Set ( ) ,
194- invalidAncestors : new Set ( ) ,
195- } ;
196-
197189describe ( "find closest editable instance selector" , ( ) => {
198190 test ( "searches closest container" , ( ) => {
199191 const instances : Instances = toMap ( [
@@ -268,173 +260,6 @@ describe("find closest editable instance selector", () => {
268260 } ) ;
269261} ) ;
270262
271- describe ( "compute instances constraints" , ( ) => {
272- const base = {
273- type : "container" ,
274- label : "" ,
275- icon : "" ,
276- } as const ;
277-
278- test ( "combine required ancestors excluding already resolved ones" , ( ) => {
279- const metas = new Map < string , WsComponentMeta > ( [
280- [ "Button" , { ...base , requiredAncestors : [ "Form" ] } ] ,
281- [ "Checkbox" , { ...base , requiredAncestors : [ "Form" , "Label" ] } ] ,
282- [ "Label" , { ...base , requiredAncestors : [ "Body" ] } ] ,
283- ] ) ;
284- // button
285- // label
286- // checkbox
287- const instances = new Map < Instance [ "id" ] , Instance > ( [
288- createInstancePair ( "button" , "Button" , [ ] ) ,
289- createInstancePair ( "label" , "Label" , [ { type : "id" , value : "checkbox" } ] ) ,
290- createInstancePair ( "checkbox" , "Checkbox" , [ ] ) ,
291- ] ) ;
292- expect (
293- computeInstancesConstraints ( metas , instances , [ "button" , "label" ] )
294- ) . toEqual ( {
295- requiredAncestors : new Set ( [ "Body" , "Form" ] ) ,
296- invalidAncestors : new Set ( ) ,
297- } ) ;
298- } ) ;
299-
300- test ( "combine invalid ancestors of all instances" , ( ) => {
301- const metas = new Map < string , WsComponentMeta > ( [
302- [ "Button" , { ...base , invalidAncestors : [ "Button" ] } ] ,
303- [ "Form" , { ...base , invalidAncestors : [ "Button" , "Form" ] } ] ,
304- ] ) ;
305- // form
306- // button
307- const instances = new Map < Instance [ "id" ] , Instance > ( [
308- createInstancePair ( "form" , "Form" , [ { type : "id" , value : "button" } ] ) ,
309- createInstancePair ( "button" , "Button" , [ ] ) ,
310- ] ) ;
311- expect ( computeInstancesConstraints ( metas , instances , [ "form" ] ) ) . toEqual ( {
312- requiredAncestors : new Set ( ) ,
313- invalidAncestors : new Set ( [ "Button" , "Form" ] ) ,
314- } ) ;
315- } ) ;
316- } ) ;
317-
318- describe ( "find closest droppable component index" , ( ) => {
319- test ( "finds container" , ( ) => {
320- expect (
321- findClosestDroppableComponentIndex ( {
322- metas : createFakeComponentMetas ( { } ) ,
323- constraints : emptyInsertConstraints ,
324- instances : new Map < Instance [ "id" ] , Instance > ( [
325- createInstancePair ( "body" , "Body" , [ { type : "id" , value : "box" } ] ) ,
326- createInstancePair ( "box" , "Box" , [ ] ) ,
327- ] ) ,
328- instanceSelector : [ "box" , "body" ] ,
329- } )
330- ) . toEqual ( 0 ) ;
331- } ) ;
332-
333- test ( "skips non containers" , ( ) => {
334- expect (
335- findClosestDroppableComponentIndex ( {
336- metas : createFakeComponentMetas ( { } ) ,
337- constraints : emptyInsertConstraints ,
338- instances : new Map < Instance [ "id" ] , Instance > ( [
339- createInstancePair ( "body" , "Body" , [ { type : "id" , value : "box" } ] ) ,
340- createInstancePair ( "box" , "Box" , [ { type : "id" , value : "text" } ] ) ,
341- createInstancePair ( "text" , "Text" , [ { type : "id" , value : "italic" } ] ) ,
342- createInstancePair ( "italic" , "Italic" , [
343- { type : "id" , value : "bold" } ,
344- ] ) ,
345- createInstancePair ( "bold" , "Bold" , [ ] ) ,
346- ] ) ,
347- instanceSelector : [ "bold" , "italic" , "text" , "box" , "body" ] ,
348- } )
349- ) . toEqual ( 2 ) ;
350- } ) ;
351-
352- test ( "considers invalid ancestors" , ( ) => {
353- expect (
354- findClosestDroppableComponentIndex ( {
355- metas : createFakeComponentMetas ( { } ) ,
356- constraints : {
357- requiredAncestors : new Set ( ) ,
358- invalidAncestors : new Set ( [ "Item" ] ) ,
359- } ,
360- instances : new Map < Instance [ "id" ] , Instance > ( [
361- createInstancePair ( "body" , "Body" , [ { type : "id" , value : "item" } ] ) ,
362- createInstancePair ( "item" , "Item" , [ { type : "id" , value : "box" } ] ) ,
363- createInstancePair ( "box" , "Box" , [ ] ) ,
364- ] ) ,
365- instanceSelector : [ "box" , "item" , "body" ] ,
366- } )
367- ) . toEqual ( 2 ) ;
368- } ) ;
369-
370- test ( "requires some ancestor" , ( ) => {
371- expect (
372- findClosestDroppableComponentIndex ( {
373- metas : createFakeComponentMetas ( { } ) ,
374- constraints : {
375- requiredAncestors : new Set ( [ "Form" ] ) ,
376- invalidAncestors : new Set ( ) ,
377- } ,
378- instances : new Map < Instance [ "id" ] , Instance > ( [
379- createInstancePair ( "body" , "Body" , [ { type : "id" , value : "box" } ] ) ,
380- createInstancePair ( "box" , "Box" , [ ] ) ,
381- ] ) ,
382- instanceSelector : [ "box" , "body" ] ,
383- } )
384- ) . toEqual ( - 1 ) ;
385- expect (
386- findClosestDroppableComponentIndex ( {
387- metas : createFakeComponentMetas ( { } ) ,
388- constraints : {
389- requiredAncestors : new Set ( [ "Form" ] ) ,
390- invalidAncestors : new Set ( ) ,
391- } ,
392- instances : new Map < Instance [ "id" ] , Instance > ( [
393- createInstancePair ( "body" , "Body" , [ { type : "id" , value : "form" } ] ) ,
394- createInstancePair ( "form" , "Form" , [ { type : "id" , value : "box" } ] ) ,
395- createInstancePair ( "box" , "Box" , [ ] ) ,
396- ] ) ,
397- instanceSelector : [ "box" , "form" , "body" ] ,
398- } )
399- ) . toEqual ( 0 ) ;
400- } ) ;
401-
402- test ( "considers both required and invalid ancestors" , ( ) => {
403- expect (
404- findClosestDroppableComponentIndex ( {
405- metas : createFakeComponentMetas ( { } ) ,
406- constraints : {
407- requiredAncestors : new Set ( [ "Form" ] ) ,
408- invalidAncestors : new Set ( [ "Box" ] ) ,
409- } ,
410- instances : new Map < Instance [ "id" ] , Instance > ( [
411- createInstancePair ( "body" , "Body" , [ { type : "id" , value : "form" } ] ) ,
412- createInstancePair ( "form" , "Form" , [ { type : "id" , value : "box" } ] ) ,
413- createInstancePair ( "box" , "Box" , [ { type : "id" , value : "div" } ] ) ,
414- createInstancePair ( "div" , "Div" , [ ] ) ,
415- ] ) ,
416- instanceSelector : [ "div" , "box" , "form" , "body" ] ,
417- } )
418- ) . toEqual ( 2 ) ;
419- expect (
420- findClosestDroppableComponentIndex ( {
421- metas : createFakeComponentMetas ( { } ) ,
422- constraints : {
423- requiredAncestors : new Set ( [ "Form" ] ) ,
424- invalidAncestors : new Set ( [ "Box" ] ) ,
425- } ,
426- instances : new Map < Instance [ "id" ] , Instance > ( [
427- createInstancePair ( "body" , "Body" , [ { type : "id" , value : "form" } ] ) ,
428- createInstancePair ( "form" , "Form" , [ { type : "id" , value : "box" } ] ) ,
429- createInstancePair ( "box" , "Box" , [ { type : "id" , value : "div" } ] ) ,
430- createInstancePair ( "div" , "Div" , [ ] ) ,
431- ] ) ,
432- instanceSelector : [ "div" , "form" , "box" , "body" ] ,
433- } )
434- ) . toEqual ( - 1 ) ;
435- } ) ;
436- } ) ;
437-
438263describe ( "insert instance children" , ( ) => {
439264 test ( "insert instance children into empty target" , ( ) => {
440265 const instances = toMap ( [ createInstance ( "body" , "Body" , [ ] ) ] ) ;
0 commit comments