@@ -16,7 +16,6 @@ import {
1616 isRootSchemaType ,
1717 LoroListSchema ,
1818 LoroMapSchema ,
19- LoroMapSchemaWithCatchall ,
2019 LoroMovableListSchema ,
2120 LoroTreeSchema ,
2221 RootSchemaType ,
@@ -43,6 +42,7 @@ import {
4342 isTreeID ,
4443 defineCidProperty ,
4544} from "./utils.js" ;
45+ import { getMapFieldSchema } from "../schema/resolver.js" ;
4646
4747/**
4848 * Finds the longest increasing subsequence of a sequence of numbers
@@ -96,33 +96,6 @@ type CommonListItemInfo = {
9696
9797type IdSelector < T > = ( item : T ) => string | undefined ;
9898
99- function getMapChildSchema (
100- schema :
101- | LoroMapSchema < Record < string , SchemaType > >
102- | LoroMapSchemaWithCatchall < Record < string , SchemaType > , SchemaType >
103- | RootSchemaType < Record < string , ContainerSchemaType > >
104- | undefined ,
105- key : string ,
106- ) : SchemaType | ContainerSchemaType | undefined {
107- if ( ! schema ) return undefined ;
108- if ( schema . type === "schema" ) {
109- return schema . definition [ key ] ;
110- }
111- if ( schema . type === "loro-map" ) {
112- if ( Object . prototype . hasOwnProperty . call ( schema . definition , key ) ) {
113- return schema . definition [ key ] ;
114- }
115- const withCatchall = schema as LoroMapSchemaWithCatchall <
116- Record < string , SchemaType > ,
117- SchemaType
118- > & { catchallType ?: SchemaType } ;
119- if ( withCatchall . catchallType ) {
120- return withCatchall . catchallType ;
121- }
122- }
123- return undefined ;
124- }
125-
12699/**
127100 * Diffs a container between two states
128101 *
@@ -1271,17 +1244,7 @@ export function diffMap<S extends ObjectLike>(
12711244 continue ;
12721245 }
12731246 // Skip ignored fields defined in schema
1274- const childSchemaForDelete = getMapChildSchema (
1275- schema as
1276- | LoroMapSchema < Record < string , SchemaType > >
1277- | LoroMapSchemaWithCatchall <
1278- Record < string , SchemaType > ,
1279- SchemaType
1280- >
1281- | RootSchemaType < Record < string , ContainerSchemaType > >
1282- | undefined ,
1283- key ,
1284- ) ;
1247+ const childSchemaForDelete = getMapFieldSchema ( schema , key ) ;
12851248 if ( childSchemaForDelete && childSchemaForDelete . type === "ignore" ) {
12861249 continue ;
12871250 }
@@ -1309,17 +1272,7 @@ export function diffMap<S extends ObjectLike>(
13091272 if ( newItem === undefined ) {
13101273 // If old item exists, we need to delete it
13111274 if ( key in oldStateObj && oldItem !== undefined ) {
1312- const childSchemaForDelete = getMapChildSchema (
1313- schema as
1314- | LoroMapSchema < Record < string , SchemaType > >
1315- | LoroMapSchemaWithCatchall <
1316- Record < string , SchemaType > ,
1317- SchemaType
1318- >
1319- | RootSchemaType < Record < string , ContainerSchemaType > >
1320- | undefined ,
1321- key ,
1322- ) ;
1275+ const childSchemaForDelete = getMapFieldSchema ( schema , key ) ;
13231276 if ( ! ( childSchemaForDelete && childSchemaForDelete . type === "ignore" ) ) {
13241277 changes . push ( {
13251278 container : containerId ,
@@ -1333,17 +1286,7 @@ export function diffMap<S extends ObjectLike>(
13331286 }
13341287
13351288 // Figure out if the modified new value is a container
1336- const childSchema = getMapChildSchema (
1337- schema as
1338- | LoroMapSchema < Record < string , SchemaType > >
1339- | LoroMapSchemaWithCatchall <
1340- Record < string , SchemaType > ,
1341- SchemaType
1342- >
1343- | RootSchemaType < Record < string , ContainerSchemaType > >
1344- | undefined ,
1345- key ,
1346- ) ;
1289+ const childSchema = getMapFieldSchema ( schema , key ) ;
13471290
13481291 // Skip ignored fields defined in schema
13491292 if ( childSchema && childSchema . type === "ignore" ) {
0 commit comments