{"version":3,"file":"EntityListSubTree.cjs","sources":["../../../../../packages/react-binding/src/coreComponents/EntityListSubTree.tsx"],"sourcesContent":["import { useConstantValueInvariant } from '@contember/react-utils'\nimport { ComponentType, ReactElement, ReactNode } from 'react'\nimport { useEntityListSubTree } from '../accessorPropagation'\nimport type { SugaredQualifiedEntityList, SugaredUnconstrainedQualifiedEntityList, TreeRootId } from '@contember/binding'\nimport { Environment, MarkerFactory, PRIMARY_KEY_NAME, TreeNodeEnvironmentFactory } from '@contember/binding'\nimport { Component } from './Component'\nimport { EntityList, EntityListBaseProps } from './EntityList'\nimport { Field } from './Field'\n\nexport interface EntityListSubTreeAdditionalProps {\n\tvariables?: Environment.ValuesMapWithFactory\n}\n\nexport type EntityListSubTreeProps<ListProps, EntityProps> = {\n\ttreeRootId?: TreeRootId\n\tchildren?: ReactNode\n} & EntityListSubTreeAdditionalProps &\n(SugaredQualifiedEntityList | SugaredUnconstrainedQualifiedEntityList) &\n(\n\t| {}\n\t| {\n\t\tlistComponent: ComponentType<ListProps & EntityListBaseProps>\n\t\tlistProps?: ListProps\n\t\t  }\n)\n\n/**\n * Creates a subtree with list of entities in current data binding context.\n *\n * @example\n * ```\n * <EntityListSubTree entities=\"Post\" />\n * ```\n *\n * @group Data binding\n */\nexport const EntityListSubTree = Component(\n\t<ListProps, EntityProps>(props: EntityListSubTreeProps<ListProps, EntityProps>) => {\n\t\tuseConstantValueInvariant(props.isCreating, 'EntityListSubTree: cannot update isCreating')\n\t\tconst accessor = useEntityListSubTree(props, ...props.treeRootId ? [props.treeRootId] : [])\n\n\t\t//  TODO revive top level hasOneRelationPath\n\t\t// {parameters.value.hasOneRelationPath.length ?\n\t\t// \t<HasOne field={parameters.value.hasOneRelationPath}>{props.children}</HasOne\n\t\t// ) :\n\t\t// \tprops.children\n\t\t// )\n\t\treturn <EntityList {...props} accessor={accessor} />\n\t},\n\t{\n\t\tgenerateBranchMarker: (props, fields, environment) => {\n\t\t\tif ('isCreating' in props && props.isCreating) {\n\t\t\t\treturn MarkerFactory.createUnconstrainedEntityListSubTreeMarker(props, fields, environment)\n\t\t\t}\n\t\t\treturn MarkerFactory.createEntityListSubTreeMarker(props, fields, environment)\n\t\t},\n\t\tstaticRender: props => (\n\t\t\t<EntityList {...props} accessor={0 as any}>\n\t\t\t\t<Field field={PRIMARY_KEY_NAME} />\n\t\t\t\t{props.children}\n\t\t\t</EntityList>\n\t\t),\n\t\tgenerateEnvironment: (props, oldEnvironment) => {\n\t\t\tconst environment = oldEnvironment.withVariables(props.variables)\n\t\t\treturn TreeNodeEnvironmentFactory.createEnvironmentForEntityListSubtree(environment, props)\n\t\t},\n\t},\n\t'EntityListSubTree',\n) as <ListProps, EntityProps>(props: EntityListSubTreeProps<ListProps, EntityProps>) => ReactElement\n"],"names":["Component","useConstantValueInvariant","useEntityListSubTree","jsxDEV","EntityList","this","MarkerFactory","Field","PRIMARY_KEY_NAME","TreeNodeEnvironmentFactory"],"mappings":";;;;;;;;;AAoCO,MAAM,oBAAoBA,UAAA;AAAA,EAChC,CAAyB,UAA0D;AACxDC,yCAAA,MAAM,YAAY,6CAA6C;AACnF,UAAA,WAAWC,0CAAqB,OAAO,GAAG,MAAM,aAAa,CAAC,MAAM,UAAU,IAAI,EAAE;AAQ1F,WAAQC,8BAAA,OAAAC,WAAA,YAAA,EAAY,GAAG,OAAO,YAAvB,QAAA,OAAA;AAAA,MAAA,UAAA;AAAA,MAAA,YAAA;AAAA,MAAA,cAAA;AAAA,IAA2C,GAAAC,MAAA;AAAA,EACnD;AAAA,EACA;AAAA,IACC,sBAAsB,CAAC,OAAO,QAAQ,gBAAgB;AACjD,UAAA,gBAAgB,SAAS,MAAM,YAAY;AAC9C,eAAOC,QAAc,cAAA,2CAA2C,OAAO,QAAQ,WAAW;AAAA,MAAA;AAE3F,aAAOA,QAAc,cAAA,8BAA8B,OAAO,QAAQ,WAAW;AAAA,IAC9E;AAAA,IACA,cAAc,CACb,UAAAH,8BAAAA,OAACC,yBAAY,GAAG,OAAO,UAAU,GAChC,UAAA;AAAA,MAACD,8BAAA,OAAAI,MAAA,OAAA,EAAM,OAAOC,QAAd,iBAAA,GAAA,QAAA,OAAA;AAAA,QAAA,UAAA;AAAA,QAAA,YAAA;AAAA,QAAA,cAAA;AAAA,MAAgC,GAAAH,MAAA;AAAA,MAC/B,MAAM;AAAA,IAAA,KAFR,QAAA,MAAA;AAAA,MAAA,UAAA;AAAA,MAAA,YAAA;AAAA,MAAA,cAAA;AAAA,IAGA,GAAAA,MAAA;AAAA,IAED,qBAAqB,CAAC,OAAO,mBAAmB;AAC/C,YAAM,cAAc,eAAe,cAAc,MAAM,SAAS;AACzD,aAAAI,mCAA2B,sCAAsC,aAAa,KAAK;AAAA,IAAA;AAAA,EAE5F;AAAA,EACA;AACD;;"}